Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 13, 2026

Each page transition was adding a new scroll listener without removing the previous one, causing memory leaks and multiple checkScroll executions per scroll event.

Changes

  • Use AbortController to manage scroll listener lifecycle
  • Abort previous controller before creating new one on page transitions
  • Pass controller signal to addEventListener to auto-remove listeners when aborted
let scrollController: AbortController | null = null;

function initHomepageHeader() {
    if (scrollController) {
        scrollController.abort();
    }
    scrollController = new AbortController();
    
    // ... setup code ...
    
    window.addEventListener('scroll', onScroll, {
        passive: true,
        signal: scrollController!.signal,
    });
}

Ensures only one active scroll listener exists at any time, preventing accumulation across Astro page transitions.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI requested a review from IEvangelist as a code owner January 13, 2026 02:58
Copilot AI changed the title [WIP] Address feedback on enhancing homepage header with search functionality Fix scroll event listener memory leak in homepage header Jan 13, 2026
@IEvangelist IEvangelist merged commit aace7bd into i-179 Jan 13, 2026
1 check passed
@IEvangelist IEvangelist deleted the copilot/sub-pr-234 branch January 13, 2026 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants