-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: fix popState
race-condition when not using SSR
#12925
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: fix popState
race-condition when not using SSR
#12925
Conversation
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
🦋 Changeset detectedLatest commit: 758a804 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I don't understand the comment where
I wonder if that's really true or why we need that to be true. Perhaps we need a separate variable to track whether the current page is initialized? I feel like this code has gotten quite complicated and there needs to be some higher-level documentation around what states are expected at what times for what reasons, etc. I'm uncomfortable with making a change that might just be papering over an issue without really understanding what the correct fix is one way or the other. Simon or Rich might have a better understanding of this code and be able to weigh in here |
Neither do I, to be honest! There are other places where we (I say we, but it's mainly @dummdidumm!) are checking for kit/packages/kit/src/runtime/client/client.js Line 550 in 758a804
kit/packages/kit/src/runtime/client/client.js Line 872 in 758a804
I think we could just get away with making the type in
URL | null . The problem is that there are many places we'd then need to add checks to see if the current page is initialized (and I think in most places, these functions are only called if the page is already initialized).
👍 One thing I've also noticed is that this kit/packages/kit/src/runtime/client/client.js Line 308 in 758a804
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
Maybe this closes #13145? |
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 ofnull
, which then causes thepopState
function to throw the following uncaught error:This is from
kit/packages/kit/src/runtime/client/client.js
Line 2234 in e41a8e2
See #12924 for a reproduction/example videos.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits