From 850c4ae6ce29aaca850204c3ddde68833ac461cb Mon Sep 17 00:00:00 2001 From: Maya Date: Tue, 2 Sep 2025 17:59:14 +0300 Subject: [PATCH] fix: navbar highlight zoooooomin probably only became an issue now because of updated packages --- src/lib/components/layout/Navbar/Base.svelte | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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}