diff --git a/src/lib/components/layout/Navbar/Base.svelte b/src/lib/components/layout/Navbar/Base.svelte index 4c39066..9c73db5 100644 --- a/src/lib/components/layout/Navbar/Base.svelte +++ b/src/lib/components/layout/Navbar/Base.svelte @@ -64,6 +64,7 @@ let links = $state([]); let container = $state(); let containerRect = $derived(container?.getBoundingClientRect()); + let isInitialized = $state(false); const linkRects = $derived(links.map((l) => l.getBoundingClientRect())); @@ -73,6 +74,16 @@ const isSecretPage = $derived(selectedIndex === -1); + $effect(() => { + if (containerRect && linkRects.length > 0 && links.length > 0) { + setTimeout(() => { + isInitialized = true; + }, 10); + } else { + isInitialized = false; + } + }); + beforeNavigate((e) => { const oldIndex = items.findIndex((i) => i.activeMatch(e.from?.url.pathname || ""), @@ -157,7 +168,7 @@
{@const linkRect = linkRects.at(selectedIndex) || linkRects[0]} - {#if linkRect} + {#if linkRect && isInitialized}