Repository navigation
fix(favorites): preserve the scroll position across a tab swap - #496
Merged
Merged
Conversation
Switching between the Stations and Routes tabs threw the rider back to the top of the page. The cause: the browser scrolls the focused tab trigger into view when the tab is activated, and the trigger strip sits at the TOP of the page - so by the time the app's click handler ran, window.scrollY was already 0 and the handler restored 0. The offset is now captured on pointerdown, which fires before focus and before the browser's scroll, so a rider deep in a list keeps their place. Each tab also remembers its own offset, and the restore waits for the document height to settle (the inactive panel is `display: none`, so the height changes across the swap and a single rAF can be clamped away). tests/favorites-tabswap.spec.ts asserted the document HEIGHT was stable, which `display: none` makes impossible - it skipped whenever the stations catalog failed to populate, so it never validated the behaviour it was written for. It now asserts the scroll position, and reproduces the browser's event order (pointerdown, focus, scroll, click) so it fails against the old code.
ciotlosm
force-pushed
the
fix/favorites-tab-scroll
branch
from
October 24, 2026 18:41
6532805 to
57b4e92
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Switching between the Stations and Routes tabs on /favorites threw the rider back to the top of the page.
The cause
The browser scrolls the focused tab trigger into view when the tab is activated, and the trigger strip sits at the top of the page - so by the time the app's click handler ran,
window.scrollYwas already0, and the handler dutifully restored0.The fix
display: none, so the height changes across the swap and a single rAF can be clamped away.The old test never tested this
tests/favorites-tabswap.spec.tsasserted the document height was stable, whichdisplay: nonemakes impossible - and it skipped whenever the stations catalog failed to populate (no feed bound in CI), so it never validated the behaviour it was written for.It now asserts the scroll position, and reproduces the browser's event order (pointerdown -> focus -> scroll -> click) so it fails against the old code:
pnpm check-> 0 errors,pnpm test-> 386 passed,pnpm build-> OK (verified on this branch in isolation).