From f00dc9a6e7f0e93dee420ee8aefc26009da40f3a Mon Sep 17 00:00:00 2001 From: Caleb Pollman Date: Wed, 19 Feb 2025 15:34:18 -0800 Subject: [PATCH] fix(docs): remove non-visible header rendering in TOC --- docs/src/components/Layout/index.tsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/src/components/Layout/index.tsx b/docs/src/components/Layout/index.tsx index a0486a0e021..d0e074eec0e 100644 --- a/docs/src/components/Layout/index.tsx +++ b/docs/src/components/Layout/index.tsx @@ -46,12 +46,22 @@ export default function Page({ ...document.querySelectorAll( `${nextRootSelector} h2[id], ${nextRootSelector} h3[id]` ), - ].map((node: HTMLElement) => ({ - id: node.id, - label: node.innerText, - level: node.nodeName, - top: node.offsetTop, - })) + ].reduce( + ( + acc: { id: string; label: string; level: string; top: number }[], + node: HTMLElement + ) => + // remove non-visible nodes that are excluded from rendering by `FilterChildren` + !node.checkVisibility() + ? acc + : acc.concat({ + id: node.id, + label: node.innerText, + level: node.nodeName, + top: node.offsetTop, + }), + [] + ) ); }); updateHeaders(); // with static rendering the mutation observer is no longer triggered on initial page view because the content has already been rendered