diff --git a/themes/gitbook/components/Catalog.js b/themes/gitbook/components/Catalog.js index 292ff7eb..df7484a6 100644 --- a/themes/gitbook/components/Catalog.js +++ b/themes/gitbook/components/Catalog.js @@ -49,8 +49,11 @@ const Catalog = ({ post }) => { } setActiveSection(currentSectionId) const index = tocIds.indexOf(currentSectionId) || 0 - if (isBrowser()) { - document?.getElementById('toc-wrapper')?.scrollTo({ top: 28 * index, behavior: 'smooth' }) + if (isBrowser() && tocIds?.length > 0) { + console.log(28 * index, index, currentSectionId) + for (const tocWrapper of document?.getElementsByClassName('toc-wrapper')) { + tocWrapper?.scrollTo({ top: 28 * index, behavior: 'smooth' }) + } } }, throttleMs)) @@ -60,7 +63,7 @@ const Catalog = ({ post }) => { } return <> -