Skip to content
Source
Sign inSign up
TanStack/router

fix(router-core): qualify pagehide event listener #8032

OpenMoonBrillante(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/8032/headopened

Summary

Qualify the pagehide listener registration with window.addEventListener.

This ensures the correct receiver is used when EventTarget.prototype.addEventListener has been patched by instrumentation libraries.

A regression assertion was added to verify that the pagehide listener is registered with window as its context.

Fixes #8024

Tests

pnpm nx run @tanstack/router-core:test:unit -- tests/scroll-restoration.test.ts

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **Bug Fixes**
  - Improved scroll restoration reliability by ensuring page navigation events are registered on the browser window.
- **Tests**
  - Added coverage confirming the scroll restoration listener is attached to the correct browser target.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Review Change Stack

      Note

      Currently processing new changes in this PR. This may take a few minutes, please wait...

      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 740f6369-21a4-4886-aeb2-1b01a8f08bf1

      📥 Commits

      Reviewing files that changed from the base of the PR and between af8dcb859a2e025740524b267d89da970d65af28 and f20e66ad24865050c97724bb50d076b6ff899075.

      📒 Files selected for processing (2)
      • packages/router-core/src/scroll-restoration.ts
      • packages/router-core/tests/scroll-restoration.test.ts
       ______________________________________
      < All those GPUs aren't just for show. >
       --------------------------------------
        \
         \   (\__/)
             (•ㅅ•)
             /   づ
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.