Skip to content

Commit 758a804

Browse files
committed
fix: fix a popState race-condition
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 the following uncaught error: ``` Uncaught (in promise) TypeError: Cannot destructure property 'href' of 'object null' as it is null. at strip_hash (url.js?v=3a24e001:84:30) at client.js?v=3a24e001:2227:52 ``` This is from https://github.com/sveltejs/kit/blob/e41a8e24b71cb9e9ee249ddfe732a3d0721d40bf/packages/kit/src/runtime/client/client.js#L2234
1 parent 2668a7d commit 758a804

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
@@ -2231,7 +2231,7 @@ function _start_router() {
22312231
const state = event.state[STATES_KEY] ?? {};
22322232
const url = new URL(event.state[PAGE_URL_KEY] ?? location.href);
22332233
const navigation_index = event.state[NAVIGATION_INDEX];
2234-
const is_hash_change = strip_hash(location) === strip_hash(current.url);
2234+
const is_hash_change = current.url ? strip_hash(location) === strip_hash(current.url) : false;
22352235
const shallow =
22362236
navigation_index === current_navigation_index && (has_navigated || is_hash_change);
22372237

0 commit comments

Comments
 (0)