Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: popstate navigation wasn't cancelling ongoing navigation() calls when landing on the same page #10727

Merged
merged 4 commits into from
Oct 9, 2023
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
Loading