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
fix(app): preserve prior scrollRestoration value across mount/unmount (#5404)
Follow-up to #5403 addressing review feedback that arrived after the
original PR was squash-merged.
Because #5403 was squash-merged, this branch's individual commits show
as new against `main`. The diff therefore covers both the feedback fix
and the original commits — the description below reflects the full diff.
## Summary
- **Preserve prior `history.scrollRestoration`** in `HomePage` and
`PlotsPage` (the new bit). Capture the value on mount and restore it on
unmount, instead of hard-setting `'auto'` — avoids clobbering a
non-default value set elsewhere.
- **Scroll-to-top on forward navigation** in `RootLayout` (carried over
from the squash-merged #5403). Skips POP navigation so browser
back/forward keeps native scroll restoration; skips when a hash anchor
is present so in-page anchors still work. Comment in the source updated
to accurately describe the SPA-PUSH cause (per review feedback).
- **Scoped `scrollRestoration='manual'`** in `HomePage`/`PlotsPage` to
those pages with cleanup on unmount, so other routes get native browser
back/forward behavior.
- **Tests:** new `RootLayout.test.tsx` (PUSH scrolls, hash skips);
extended `HomePage.test.tsx` and `PlotsPage.test.tsx` covering
mount/unmount restoration for both `'auto'` and `'manual'` prior values.
## User-facing behavior
- Clicking a footer link like `/legal` from a long page now lands at the
top.
- Browser back/forward to a route without custom scroll handling
restores the previous position.
- Pages that manage their own saved scroll (`HomePage`, `PlotsPage`)
still restore from their persisted state.
## Test plan
- [ ] `cd app && yarn test` — all suites pass
- [ ] Navigate `/plots` → footer `/legal` lands at top
- [ ] Browser back from `/legal` to `/plots` restores prior scroll
- [ ] In-page hash anchor (e.g. `/about#section`) still scrolls to
anchor
---------
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments