From 27de1cd01dab8e4718b413f5fe11043e2be8df63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 25 Mar 2025 15:39:45 +0100 Subject: [PATCH] Default to the first ID as being active in scroll detection (#3036) --- packages/gitbook/src/components/hooks/useScrollActiveId.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/gitbook/src/components/hooks/useScrollActiveId.ts b/packages/gitbook/src/components/hooks/useScrollActiveId.ts index 96b986eac..eacfdcc26 100644 --- a/packages/gitbook/src/components/hooks/useScrollActiveId.ts +++ b/packages/gitbook/src/components/hooks/useScrollActiveId.ts @@ -12,11 +12,12 @@ export function useScrollActiveId( ) { const { rootMargin, threshold = 0.5 } = options; - const [activeId, setActiveId] = React.useState(null); + const [activeId, setActiveId] = React.useState(ids[0]); const sectionsIntersectingMap = React.useRef>(new Map()); React.useEffect(() => { - setActiveId(null); + const defaultActiveId = ids[0]; + setActiveId((activeId) => (ids.indexOf(activeId) !== -1 ? activeId : defaultActiveId)); if (typeof IntersectionObserver === 'undefined') { return;