Skip to content

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

Open
MoonBrillante wants to merge 1 commit into
TanStack:mainfrom
MoonBrillante:fix-scroll-restoration-pagehide
Open

fix(router-core): qualify pagehide event listener#8032
MoonBrillante wants to merge 1 commit into
TanStack:mainfrom
MoonBrillante:fix-scroll-restoration-pagehide

Conversation

@MoonBrillante

@MoonBrillante MoonBrillante commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

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 -->

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

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 af8dcb8 and f20e66a.

📒 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 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.

scroll-restoration registers pagehide with a bare addEventListener, which breaks under a patched EventTarget

1 participant