Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1693,7 +1694,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