mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-22 18:43:29 +00:00
be0d5d25f0
A cross-page anchor link navigated to the right page but stayed at the top. GitBook's `scrollToHash` scrolled once, but a soft navigation delivers the destination asynchronously — content keeps mounting and reflowing for a few hundred ms after the URL changes — so the single scroll landed before the target reached its final position, and #4089 routed cross-section navigations through it. It also scrolled to the top on a transiently-empty hash context. - scrollToHash re-scrolls to the target on each DOM change until the DOM goes quiet, mirroring the fragment scrolling the browser does for free during a full page load. It bails if the visitor scrolls, so we never fight them. - useScrollPage decides the hash from the context value for same-page anchors (authoritative, set on click) and from `window.location.hash` for cross-page navigations (where the context hash is transiently empty during the remount). Next keeps handling the baseline scroll (top on plain/query navigations, the top fallback for missing anchors); GitBook only re-asserts the hash scroll it would otherwise land too early on. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>