Skip to content

Commit

Permalink
chore: Wait for hash element to be created
Browse files Browse the repository at this point in the history
  • Loading branch information
PuruVJ committed Jun 22, 2023
1 parent 0b714b7 commit 1f883c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-taxis-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/site-kit': patch
---

Wait for hash element to be created
6 changes: 4 additions & 2 deletions packages/site-kit/src/lib/docs/DocsOnThisPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,7 +41,7 @@
highlight();
});
function update() {
async function update() {
const contentEl = /** @type {HTMLElement | null} */ (document.querySelector('.content'));
if (!contentEl) return;
Expand All @@ -59,6 +59,8 @@
const hash = $page.url.hash.replace(/^#/, '');
const el = document.getElementById(hash);
await tick();
el?.scrollIntoView({ behavior: 'auto', block: 'start' });
}
Expand Down

0 comments on commit 1f883c9

Please sign in to comment.