mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-18 00:25:07 +00:00
0146877fc1
Cross-page anchor links (e.g. a homepage card linking to `/page#heading`) landed at the top of the destination page on soft navigation, while the same URL loaded directly scrolled to the heading correctly. `useScrollToHash` (the per-page safety net in PageClientLayout that scrolls once the page blocks are rendered) only depended on the navigation hash. The hash is set at click time while the previous page is still mounted, so the effect fired before the target element existed. Because sibling pages share the same `[pagePath]` route, PageClientLayout is reused rather than remounted, so the effect never re-ran once the destination content committed to the DOM. Add `pathname` as a dependency so the scroll is re-attempted when the destination page commits and the target heading is present. The `if (hash)` guard is unchanged, so hash-less navigations still scroll to top via ScrollPage and back/forward restoration is unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TpGe6QkAF4Y1HDGUD4vbke