Skip to content

Commit

Permalink
fix: popstate navigation wasn't cancelling ongoing navigation() c…
Browse files Browse the repository at this point in the history
…alls when landing on the same page (#10727)
  • Loading branch information
JakeBeaver authored Oct 9, 2023
1 parent f8aacaf commit 9bc6e62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/neat-chicken-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: cancel ongoing navigation when the browser back button is hit to prevent an incorrect page from being rendered
4 changes: 3 additions & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,7 @@ export function create_client(app, target) {
});

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

0 comments on commit 9bc6e62

Please sign in to comment.