Skip to content

Prevent multiple script initializations across SPA navigations #2

Description

@cagandhi

Description

The mainScript can be executed multiple times due to:

  • webNavigation triggers
  • GitHub SPA navigation
  • manual reinjection

Issues caused

  • Duplicate polling loops (setInterval)
  • Multiple requestAnimationFrame loops
  • Re-attached event listeners
  • Unpredictable behavior and performance degradation

Expected Behavior

Script should initialize only once per page lifecycle.

Proposed Fix

Add a global guard at the top of the script:

if (window.__ghSingleFileInitialized) return;
window.__ghSingleFileInitialized = true;

Why this matters

  • Prevents memory leaks
  • Ensures deterministic behavior
  • Required for Chrome Web Store quality standards

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions