You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scrolling during initial page load can send the visitor back to the top when hydration finishes. On the homepage preview in Chrome, scrolling to 3,860 px before hydration finished reset the position to 0 px without a URL or page height change.
Patch the pinned @tanstack/router-core to skip the default window reset on the first SSR-rendered location. Keep the current offset available for Back navigation and preserve stored window and element offsets, hash links, and normal navigation resets.
Related upstream fix: TanStack/router#8934. Remove the local patch once the site adopts a Router release with the fix.
Verification
Reproduced the reset against the unpatched Router. The same regression check passed with the patch for both ESM and CJS, covering hydration, forward navigation, Back, cached offsets, hash links, and an initial client-only load.
Frozen lockfile validation, type checking, lint, and desktop tests passed.
The broader suites ran with the Node TS loader after the TSX CLI hit a socket permission error. Five tests across the unit and chat suites were blocked by local socket or Chrome launch restrictions.
Summary by CodeRabbit
Bug Fixes
Preserved the current scroll position during initial hydration instead of unexpectedly scrolling the window to the top.
Kept nonzero window scroll positions available for scroll tracking; other navigation and scroll-to-top behavior remains unchanged.
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
No actionable comments were generated in the recent review.
Walkthrough
The router-core patch identifies the first render with identical source and destination locations as initial hydration. It skips scrolling the window to the top when the window has not been restored. The workspace file registers the patch for the specified router-core version.
Changes: Hydration scroll restoration
Layer / File(s)
Summary
Preserve scroll during initial hydration patches/@tanstack__router-core@1.171.34.patch, pnpm-workspace.yaml
The source implementation and CJS and ESM bundles skip window scroll-to-top on initial hydration when the window has not been restored. When scroll tracking is enabled and either window coordinate is nonzero, the document is tracked. Other renders retain the existing window scroll behavior, and scroll-to-top elements are still processed. The workspace registers the patch for @tanstack/router-core@1.171.34.
This adds a local patch that stops the first SSR hydration from resetting the window scroll to the top. Normal navigation behavior is unchanged. No concrete merge-blocking risk was found, and the patch should be removed once an upstream Router release includes the fix.
Pre-merge checks: 3 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Linked Issues check
Direct issue #8934 requires that hydrate() set router._scroll.n = false only in the !needsClientLoad branch, so the first render after hydration skips the scroll reset. The PR instead patches @tanstac…
Confirm from the patch hunks in src/scroll-restoration.ts (CJS and ESM bundles) that the skip applies only when the hydrated match does not need a client load. Confirm that element scroll restoration still runs for a scroll container render…
Passed checks: 3 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "Preserve scroll during initial hydration" matches the main change. The raw summary says the first onRendered event during hydration no longer scrolls the window to the top when the window h…
Out of Scope Changes check
The changed files in the summary are the router-core patch file and the pinned patch entry in pnpm-workspace.yaml. The patch edits the scroll restoration logic that issue #8934 covers. The PR descript…
Full details: Title check
Explanation
The title "Preserve scroll during initial hydration" matches the main change. The raw summary says the first onRendered event during hydration no longer scrolls the window to the top when the window has not already been restored. The linked issue #8934 asks for the same behavior: hydration keeps scroll position when it resolves the server-rendered location. The title is short, specific, and free of noise.
Full details: Out of Scope Changes check
Explanation
The changed files in the summary are the router-core patch file and the pinned patch entry in pnpm-workspace.yaml. The patch edits the scroll restoration logic that issue #8934 covers. The PR description states that the patch is temporary and points to the upstream fix. The pnpm-lock.yaml change is excluded from review under the ignored_files rule, so it is not assessed here. No unrelated changes appear in the summary.
Full details: Linked Issues check
Explanation
Direct issue #8934 requires that hydrate() set router._scroll.n = false only in the !needsClientLoad branch, so the first render after hydration skips the scroll reset. The PR instead patches @tanstack/router-core (patches/@tanstack__router-core@1.171.34.patch). Per the raw summary, the patch treats the first onRendered event as hydration when fromLocation and toLocation match. It skips the window scroll-to-top when the window is not already restored. It adds the document to tracked scroll targets when scroll tracking is enabled and a window coordinate is nonzero. The summary does not show whether the patch gates on needsClientLoad, so the ssr: false and 'data-only' behavior is unverified. The summary also does not show whether element scroll entries are restored when a scroll container renders after the inline restoration script. The issue names this as an untested regression. No test files appear in the summary. The issue's hydrate.test.ts and scroll-restoration-reload e2e expectations are therefore not shown as implemented. The PR description reports local checks, but those are not committed automated tests in the reviewed change.
Resolution
Confirm from the patch hunks in src/scroll-restoration.ts (CJS and ESM bundles) that the skip applies only when the hydrated match does not need a client load. Confirm that element scroll restoration still runs for a scroll container rendered after the inline script. Identify where the regression tests for the no-scroll-reset case and the reload restoration case are committed, or state that they are not part of this PR.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: f6c12ae5-f92e-420d-84dd-00f1a7d1830c
Commits
Reviewing files that changed from the base of the PR and between 9cf50da and a76e501.
Files ignored due to path filters: 1
pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 2
patches/@tanstack__router-core@1.171.34.patch
pnpm-workspace.yaml
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Scrolling during initial page load can send the visitor back to the top when hydration finishes. On the homepage preview in Chrome, scrolling to 3,860 px before hydration finished reset the position to 0 px without a URL or page height change.
Patch the pinned
@tanstack/router-coreto skip the default window reset on the first SSR-rendered location. Keep the current offset available for Back navigation and preserve stored window and element offsets, hash links, and normal navigation resets.Related upstream fix: TanStack/router#8934. Remove the local patch once the site adopts a Router release with the fix.
Verification
Summary by CodeRabbit