Skip to content

Conversation

PatrickG
Copy link
Member

@PatrickG PatrickG commented Feb 7, 2024

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

// Reset `form` on navigation, but not invalidation

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


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:

  • 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • 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

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

Copy link

changeset-bot bot commented Feb 7, 2024

🦋 Changeset detected

Latest commit: ba17182

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

@benmccann benmccann requested a review from dummdidumm February 18, 2024 19:27
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You hunch is right. I think the better fix is to add similar logic to the form logic: get_navigation_result_from_branch optionally accepts a state property, which defaults to the empty object. It's set nowhere except the call site where that form invalidate logic is, i.e. state: invalidating ? page.state : {}

@PatrickG
Copy link
Member Author

PatrickG commented Mar 6, 2024

@dummdidumm Do you mean like this?

@teemingc teemingc changed the title fix: preserve state when invalidating fix: preserve $page.state when invalidating Mar 18, 2024
@AndreasHald

This comment was marked as duplicate.

@teemingc teemingc requested a review from dummdidumm April 3, 2024 13:08
@ConProgramming
Copy link
Contributor

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
Copy link
Contributor

This seems to resolve it #11956 (comment)
Can this be merged

@PatrickG
Copy link
Member Author

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.

@craig-jennings

This comment was marked as duplicate.

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense, but will discuss with other maintainer to get agreement on whether this is a bugfix or expected behavior

@teemingc teemingc added the bug Something isn't working label Oct 9, 2024
@craig-jennings

This comment was marked as duplicate.

@PatrickG
Copy link
Member Author

PatrickG commented Aug 5, 2025

With the merge of the remote functions PR, this is basically implemented in the (hacky) way I tried first.

// This is a bit hacky but allows us not having to pass that boolean around, making things harder to reason about

But reset_page_state is only false when calling refreshAll(). IMO it should default to false when calling invalidate(...) and invalidateAll() as well, with an option to enable resetting the page state.
I'll update this PR.

@svelte-docs-bot
Copy link

@PatrickG PatrickG requested review from dummdidumm and teemingc August 5, 2025 19:50
@teemingc teemingc removed the bug Something isn't working label Aug 6, 2025
@Rich-Harris Rich-Harris added this to the 3.0 milestone Aug 20, 2025
@Rich-Harris Rich-Harris added the needs-decision Not sure if we want to do this yet, also design work needed label Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-decision Not sure if we want to do this yet, also design work needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$page.state is cleared when invalidate is invoked

7 participants