-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[fix] break out of 404 SPA loop #6918
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
Conversation
🦋 Changeset detectedLatest commit: c16fd2c 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 remember this being finicky when I last looked into it, but: could we handle the SPA initialisation case differently to how we handle hydration and navigation, and never fall back to the server in that case? That way we don't need to worry about infinite loops, or keeping track in |
That could be another possible solution. We would need to make sure it works for cases where only part of your app is an SPA, too, not sure how that would look like - possibly something like checking that when doing a root layout reload in the error case that the root layout tells you this is csr only. |
In theory we know if a given page load is an SPA page load, because kit/packages/kit/src/runtime/client/start.js Lines 30 to 34 in 3c3b6a8
|
Good point. Hydrate is false, and the router running means SPA mode. So therefore before falling back to the server we would check if we reload the url we are already on, and if so, prevent that. Essentially the existing SPA check but in a different place. |
071ac15
to
e59391b
Compare
pushed up a WIP, code is more convoluted than I'd like and the error is incorrect in case of a root error (404 instead of whatever it should be instead), will look at this again tomorrow |
…is resulted in the message always being "Internal Error", for 404s, too
Turns out the code was correct already, but I got confused by wrong error messages - turns out, it was/is buggy both on the client and the server:
|
Should be good to go now. Besides handling the SPA loop this also fixed some bugs around error handling. |
Fixes #6854, but not other cases - when the root +layout(.server).js fails, we also go back to the server for a reload, which would also result in a loop. This could be handled maybe through storing some state in session storage and checking that upon entering an error state again.
Opening this PR regardless to get some discussion going - if we want to explictitly only handle this case for now, or go with a more general solution.
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. All changesets should bepatch
until SvelteKit 1.0