Skip to content

Commit 9bc6e62

Browse files
authored
fix: popstate navigation wasn't cancelling ongoing navigation() calls when landing on the same page (#10727)
1 parent f8aacaf commit 9bc6e62

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.changeset/neat-chicken-turn.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: cancel ongoing navigation when the browser back button is hit to prevent an incorrect page from being rendered

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,7 @@ export function create_client(app, target) {
16621662
});
16631663

16641664
addEventListener('popstate', async (event) => {
1665+
token = {};
16651666
if (event.state?.[INDEX_KEY]) {
16661667
// if a popstate-driven navigation is cancelled, we need to counteract it
16671668
// with history.go, which means we end up back here, hence this check
@@ -1695,7 +1696,8 @@ export function create_client(app, target) {
16951696
history.go(-delta);
16961697
},
16971698
type: 'popstate',
1698-
delta
1699+
delta,
1700+
nav_token: token
16991701
});
17001702
} else {
17011703
// since popstate event is also emitted when an anchor referencing the same

0 commit comments

Comments
 (0)