From c87cdc8af4deac5de79c5bf7a8e162e17bdf4372 Mon Sep 17 00:00:00 2001 From: Claire Chabas Date: Thu, 26 Feb 2026 13:39:52 +0000 Subject: [PATCH] Fix text fragment navigation --- packages/gitbook/src/components/hooks/useHash.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/gitbook/src/components/hooks/useHash.tsx b/packages/gitbook/src/components/hooks/useHash.tsx index fecbb9d7e5..822bf47797 100644 --- a/packages/gitbook/src/components/hooks/useHash.tsx +++ b/packages/gitbook/src/components/hooks/useHash.tsx @@ -27,7 +27,16 @@ function getHash(): string | null { if (typeof window === 'undefined') { return null; } - return window.location.hash.slice(1); + + const hash = window.location.hash.slice(1); + + // We ignore text fragments (i.e. :~:text=) because they are not a classic hash navigation + // and we don't want to trigger scroll or other side effects on them. + if (hash.startsWith(':~:text=')) { + return null; + } + + return hash || null; } export const NavigationStatusProvider: React.FC = ({ children }) => {