Skip to content

Commit 102aecf

Browse files
fix: wait for commit promise instead of settled (#14818)
1 parent 9d66c37 commit 102aecf

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

.changeset/eager-experts-roll.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: wait for commit promise instead of `settled`

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,10 @@ async function navigate({
16891689

16901690
navigation_result.props.page.state = state;
16911691

1692+
/**
1693+
* @type {Promise<void> | undefined}
1694+
*/
1695+
let commit_promise;
16921696
if (started) {
16931697
const after_navigate = (
16941698
await Promise.all(
@@ -1722,7 +1726,7 @@ async function navigate({
17221726
const fork = load_cache_fork && (await load_cache_fork);
17231727

17241728
if (fork) {
1725-
void fork.commit();
1729+
commit_promise = fork.commit();
17261730
} else {
17271731
root.$set(navigation_result.props);
17281732
}
@@ -1738,9 +1742,9 @@ async function navigate({
17381742
const promises = [tick()];
17391743

17401744
// need to render the DOM before we can scroll to the rendered elements and do focus management
1741-
// svelte.settled is only available in Svelte 5
1742-
if (/** @type {any} */ (svelte).settled) {
1743-
promises.push(/** @type {any} */ (svelte).settled());
1745+
// so we wait for the commit if there's one
1746+
if (commit_promise) {
1747+
promises.push(commit_promise);
17441748
}
17451749
// we still need to await tick everytime because if there's no async work settled resolves immediately
17461750
await Promise.all(promises);

0 commit comments

Comments
 (0)