kit icon indicating copy to clipboard operation
kit copied to clipboard

fix: preserve $page.state when invalidating

Open PatrickG opened this issue 1 year ago • 6 comments

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 form on 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 test and lint the project with pnpm lint and pnpm 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 changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • [x] Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

PatrickG avatar Feb 07 '24 10:02 PatrickG

🦋 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

changeset-bot[bot] avatar Feb 07 '24 10:02 changeset-bot[bot]

@dummdidumm Do you mean like this?

PatrickG avatar Mar 06 '24 17:03 PatrickG

@PatrickG @dummdidumm anything I can do to help with this PR? we have this issue aswell.

AndreasHald avatar Apr 02 '24 07:04 AndreasHald

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.

ConProgramming avatar Apr 25 '24 15:04 ConProgramming

This seems to resolve it https://github.com/sveltejs/kit/issues/11956#issuecomment-2016009655 Can this be merged

ConProgramming avatar Apr 25 '24 15:04 ConProgramming

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.

PatrickG avatar Apr 27 '24 07:04 PatrickG