diff --git a/.changeset/smooth-taxis-cover.md b/.changeset/smooth-taxis-cover.md new file mode 100644 index 00000000..3d860e28 --- /dev/null +++ b/.changeset/smooth-taxis-cover.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/site-kit': patch +--- + +Wait for hash element to be created diff --git a/packages/site-kit/src/lib/docs/DocsOnThisPage.svelte b/packages/site-kit/src/lib/docs/DocsOnThisPage.svelte index 4346b839..307477ac 100644 --- a/packages/site-kit/src/lib/docs/DocsOnThisPage.svelte +++ b/packages/site-kit/src/lib/docs/DocsOnThisPage.svelte @@ -3,7 +3,7 @@ import { base } from '$app/paths'; import { page } from '$app/stores'; import { root_scroll } from '$lib/actions'; - import { afterUpdate, createEventDispatcher, onMount } from 'svelte'; + import { afterUpdate, createEventDispatcher, onMount, tick } from 'svelte'; /** @type {import('./types').Page} */ export let details; @@ -41,7 +41,7 @@ highlight(); }); - function update() { + async function update() { const contentEl = /** @type {HTMLElement | null} */ (document.querySelector('.content')); if (!contentEl) return; @@ -59,6 +59,8 @@ const hash = $page.url.hash.replace(/^#/, ''); const el = document.getElementById(hash); + + await tick(); el?.scrollIntoView({ behavior: 'auto', block: 'start' }); }