From f7c4538b16cb985a417fc984f37bc076faa3cd41 Mon Sep 17 00:00:00 2001 From: Claire Chabas Date: Thu, 26 Feb 2026 12:27:04 +0000 Subject: [PATCH] Prevent hash link scroll to top in Safari (#4055) --- packages/gitbook/src/components/hooks/useScrollPage.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/gitbook/src/components/hooks/useScrollPage.ts b/packages/gitbook/src/components/hooks/useScrollPage.ts index a63159fb5..d6b2e0366 100644 --- a/packages/gitbook/src/components/hooks/useScrollPage.ts +++ b/packages/gitbook/src/components/hooks/useScrollPage.ts @@ -27,6 +27,13 @@ export function useScrollPage() { return; } + // On initial load `previousHash` can be undefined, + // but if the URL contains a fragment (hash), + // we don't override native anchor scrolling + if (!previousHash && window.location.hash) { + return; + } + window.scrollTo(0, 0); }, [hash, previousHash]); }