diff --git a/packages/client/src/components/Component.svelte b/packages/client/src/components/Component.svelte index 31f3cc3db6..94e7587010 100644 --- a/packages/client/src/components/Component.svelte +++ b/packages/client/src/components/Component.svelte @@ -475,7 +475,7 @@ node.style.scrollMargin = "100px" node.scrollIntoView({ behavior: "smooth", - block: "start", + block: "nearest", inline: "start", }) } diff --git a/packages/client/src/components/app/Layout.svelte b/packages/client/src/components/app/Layout.svelte index b7aff4047a..5207892e42 100644 --- a/packages/client/src/components/app/Layout.svelte +++ b/packages/client/src/components/app/Layout.svelte @@ -73,18 +73,20 @@ ) $: autoCloseSidePanel = !$builderStore.inBuilder && $sidePanelStore.open - // Scroll navigation into view if selected + // Scroll navigation into view if selected. + // Memoize into a primitive to avoid spamming this whenever builder store + // changes. + $: selected = + $builderStore.inBuilder && + $builderStore.selectedComponentId === "navigation" $: { - if ( - $builderStore.inBuilder && - $builderStore.selectedComponentId === "navigation" - ) { + if (selected) { const node = document.getElementsByClassName("nav-wrapper")?.[0] if (node) { node.style.scrollMargin = "100px" node.scrollIntoView({ behavior: "smooth", - block: "start", + block: "nearest", inline: "start", }) }