Commit 42142c2
committed
fix(router): scroll to top on cache-miss popstate
Companion to the previous commit. Setting history.scrollRestoration
= 'manual' takes the browser out of the scroll-restoration game on
back/forward — which is great when we have a cached snapshot (we
restore exactly where the user left off) but leaves the cache-miss
case unhandled. Without an explicit scrollTo, the cache-miss
popstate would leave scroll wherever the user was on the page they
popped FROM, which is jarring.
Adds an explicit window.scrollTo(0, 0) in the cache-miss branch of
performNavigation's popstate path — fetchAndApply itself skips its
scroll block when recordHistory=false (which is always the case for
popstate), so this is the only place to put it.
This matches what browser-native scroll restoration would do for a
history entry it has no saved scroll for. The cached-hit branch is
unchanged.1 parent 5a3b684 commit 42142c2
1 file changed
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
612 | 619 | | |
613 | 620 | | |
614 | 621 | | |
| |||
0 commit comments