toc
All checks were successful
Build & Deploy KLZ Cables / build-and-deploy (push) Successful in 3m39s

This commit is contained in:
2026-01-27 10:26:17 +01:00
parent 12501ea51a
commit 20d7d8405a
2 changed files with 32 additions and 16 deletions

View File

@@ -19,7 +19,7 @@ export default function TableOfContents({ headings, locale }: TableOfContentsPro
useEffect(() => {
const observerOptions = {
rootMargin: '-100px 0% -80% 0%',
rootMargin: '-10% 0% -70% 0%',
threshold: 0
};
@@ -31,12 +31,18 @@ export default function TableOfContents({ headings, locale }: TableOfContentsPro
});
}, observerOptions);
const elements = headings.map((h) => document.getElementById(h.id));
elements.forEach((el) => {
if (el) observer.observe(el);
});
// Use a small delay to ensure MDX content is rendered and IDs are present
const timer = setTimeout(() => {
const elements = headings.map((h) => document.getElementById(h.id));
elements.forEach((el) => {
if (el) observer.observe(el);
});
}, 500);
return () => observer.disconnect();
return () => {
clearTimeout(timer);
observer.disconnect();
};
}, [headings]);
if (headings.length === 0) return null;