Skip to content

Commit 1bedcc1

Browse files
authored
fix: fix a popState race-condition (#12925)
When loading a non-SSR page and pressing the browser's back button while the page is still loading, it's possible for `current.url` to still be the default value of `null`, which then causes the `popState` function to throw. We therefore guard against that. Fixes #12924
1 parent e201fa9 commit 1bedcc1

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

.changeset/angry-months-speak.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: fix race-condition when not using SSR when pressing back before initial load

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,7 @@ function _start_router() {
23302330
const state = event.state[STATES_KEY] ?? {};
23312331
const url = new URL(event.state[PAGE_URL_KEY] ?? location.href);
23322332
const navigation_index = event.state[NAVIGATION_INDEX];
2333-
const is_hash_change = strip_hash(location) === strip_hash(current.url);
2333+
const is_hash_change = current.url ? strip_hash(location) === strip_hash(current.url) : false;
23342334
const shallow =
23352335
navigation_index === current_navigation_index && (has_navigated || is_hash_change);
23362336

0 commit comments

Comments
 (0)