fix: preserve $page.state when invalidating
Fix #11783
I'm not sure if this is the correct fix or if it should be fixed in load_route()/get_navigation_result_from_branch() because this line
https://github.com/sveltejs/kit/blob/c749e85d2502d5eac03f739c8f18a2f3a4dcb13e/packages/kit/src/runtime/client/client.js#L988
threw me off a bit.
Reset
formon navigation, but not invalidation
This is what we need for the page state as well.
Changing this line https://github.com/sveltejs/kit/blob/c749e85d2502d5eac03f739c8f18a2f3a4dcb13e/packages/kit/src/runtime/client/client.js#L531 to
state: page?.state || {},
Seems to pass all tests as well. But I'm not sure if this could lead to unexpected behavior.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it solves.
- [x] Ideally, include a test that fails without this PR but passes with it.
Tests
- [x] Run the tests with
pnpm testand lint the project withpnpm lintandpnpm check
Changesets
- [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.
Edits
- [x] Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.
🦋 Changeset detected
Latest commit: 3c47049fb47f21af28830a5c631ec2786d41921c
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| @sveltejs/kit | Patch |
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
@dummdidumm Do you mean like this?
@PatrickG @dummdidumm anything I can do to help with this PR? we have this issue aswell.
Just ran into this. Would love to see a fix. The native history.state still has the right data event though $page.state does not.
This seems to resolve it https://github.com/sveltejs/kit/issues/11956#issuecomment-2016009655 Can this be merged
This seems to resolve it #11956 (comment) Can this be merged
This PR does not fix #11956. It only fixes losing $page.state after invalidating.
An empty $page.state on the initial load is by design.
I think it should be configurable, because it does not fit all use cases.