mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-20 01:25:16 +00:00
c7f0daa4d3
The sidebar table of contents lives in the site layout, whose client subtree is remounted on client-side navigation (already documented in useClearRouterCache, Next.js #67542). PageGroupItem and ToggleableLinkItem kept their expand/collapse state in component-local useState/useRef, so every navigation reset it: top-level groups snapped back open, nested groups re-derived from the freshly-mounting active path, and the descendants' enter animation replayed each time - which read as the sidebar flickering / losing its expanded context. Move the groups' open/collapsed state into a module-level store keyed by page id so it survives the navigation remount (mirroring the existing module-level workaround in useClearRouterCache and the zustand store in useCurrentPage). Until the visitor toggles a group it follows the active page; once toggled, their choice is remembered for the session. Also set AnimatePresence initial={false} so an already-open group does not replay its expand animation on mount. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaBLy53zu9DTce9sZhaARf