Skip to content

fix: keep restored scroll - #97

Merged
lukeed merged 1 commit into
mainfrom
fix/manual-scroll
Nov 3, 2026
Merged

lukeed merged 1 commit into
mainfrom
fix/manual-scroll

Conversation

@lukeed

@lukeed lukeed commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Summary

Going back to a page that was scrolled, such as a list scrolled half way, showed the page at the right place, then jumped to the top.

The client restores the scroll of each page itself, in the swap. But it intercepted each navigation with the default scroll behavior of the Navigation API, "after-transition", so the browser scrolled again once the navigation settled. A trace of history.back() on a page restored to y=4962: the client scrolls there at 68 ms, the page is at y=0 at navigatesuccess, and a later scroll puts it back. Depending on timing, the page can stay at the top.

  • The client intercepts with scroll: 'manual', so only its own restore runs: the saved place on back and forward, the hash target or the top on push and replace.
  • Docs: the Scroll restoration section says so.

This touches the same event.intercept() call as #92, so whichever merges second needs a small rebase.

Performance

Client runtime, minified and gzipped: 3,371 B → 3,376 B.

Test plan

  • Push and traverse navigations intercept with scroll: 'manual'
  • In Chrome 156, with bongo dev: back to a list scrolled to y=6694 stays at 6694 through navigatesuccess (on main, it is at 0 there); a link from the list still lands at the top of the new page
  • bun run build, bun test, bunx tsc -p ., bunx tsc -p build

The client restores the scroll of a page in the swap, but it
intercepted each navigation with the default scroll behavior,
"after-transition". The browser then scrolled again once the
navigation settled, so going back to a list scrolled half way
showed the right place, then jumped to the top. The client now
intercepts with scroll: 'manual'.
@lukeed
lukeed force-pushed the fix/manual-scroll branch from 30cc6a9 to e94fd3f Compare November 3, 2026 02:39
@lukeed
lukeed merged commit b749beb into main Nov 3, 2026
4 checks passed
@lukeed
lukeed deleted the fix/manual-scroll branch November 3, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant