mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 10:03:31 +00:00
06132fe0f0
The first attempt (re-running useScrollToHash on `pathname`) had no effect: the root-layout `ScrollPage` hook already called `scrollToHash` on every hash+pathname change, so the scroll was firing — but Next's own default post-navigation scroll (App Router hash handling is unreliable, see useHash / vercel/next.js#49465) runs after it and scrolls to top, overriding us. Same-page anchors are unaffected because Link.tsx handles those manually with preventDefault (no NextLink scroll), and direct URL loads work via the browser's native hash scroll — which matches the reported behavior. Set `scroll={false}` on the internal NextLink so Next stops managing scroll on client-side navigations; GitBook's ScrollPage then owns it (scroll to the hash when present, else to the top). Revert the redundant `pathname` dependency added in the previous commit. Not verified in a browser: this sandbox's network policy blocks the preview deployment and the GitBook API, so it needs a browser check on a site with cross-page anchor links (e.g. n8n) plus a regression pass on ordinary navigation scroll-to-top and back/forward restoration. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TpGe6QkAF4Y1HDGUD4vbke