Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/scroll-restoration-browser-default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/router-core': patch
---

Stop forcing `history.scrollRestoration = 'manual'` when scroll restoration is enabled. The browser's native restoration runs before first paint, so forcing manual mode broke iOS Safari swipe-back previews and made Chrome paint at the top and snap down on hard refresh; the router's own restoration still runs afterwards and still restores individual scroll containers.
2 changes: 0 additions & 2 deletions packages/router-core/src/scroll-restoration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ export function setupScrollRestoration(router: AnyRouter, force?: boolean) {
scroll.restoration = true
ignoreScroll = false

history.scrollRestoration = 'manual'

document.addEventListener(
'scroll',
(event) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/router-core/tests/scroll-restoration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ describe('setupScrollRestoration', () => {

expect(router._scroll.restoring).toBe(true)
expect(router._scroll.restoration).toBe(true)
expect(window.history.scrollRestoration).toBe('manual')
// The browser's own restoration stays on: it handles the window before
// first paint (Safari swipe-back previews, hard refresh); the router only
// corrects afterwards and restores individual scroll containers.
expect(window.history.scrollRestoration).toBe('auto')
expect(
windowAddEventListener.mock.calls.some(([event]) => event === 'pagehide'),
).toBe(true)
Expand Down