Skip to content

Commit 1f6fb19

Browse files
fix: await for settled instead of tick in navigate (#14800)
1 parent 9d8489a commit 1f6fb19

File tree

4 files changed

+163
-151
lines changed

4 files changed

+163
-151
lines changed

.changeset/cold-islands-tell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: await for `settled` instead of `tick` in navigate

packages/kit/src/runtime/client/client.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,8 +1701,15 @@ async function navigate({
17011701

17021702
const { activeElement } = document;
17031703

1704+
const promises = [tick()];
1705+
17041706
// need to render the DOM before we can scroll to the rendered elements and do focus management
1705-
await tick();
1707+
// svelte.settled is only available in Svelte 5
1708+
if (/** @type {any} */ (svelte).settled) {
1709+
promises.push(/** @type {any} */ (svelte).settled());
1710+
}
1711+
// we still need to await tick everytime because if there's no async work settled resolves immediately
1712+
await Promise.all(promises);
17061713

17071714
// we reset scroll before dealing with focus, to avoid a flash of unscrolled content
17081715
let scroll = popped ? popped.scroll : noscroll ? scroll_state() : null;

0 commit comments

Comments
 (0)