Skip to content

$page.state is cleared when invalidate is invoked #11783

Description

@aradalvand

Describe the problem

The new shallow routing feature is pretty useful, but one thing I've just stumbled into and was surprised by is the fact that calling invalidate or invalidateAll, in addition to re-running the load functions, also clears $page.state (that means it destroys any "shallow routes" that might've been set); and it doesn't create a new history entry either, which is extra weird, it means the current history entry will still remain associated with the $page.state prior to the invalidateAll call, but the $page.state itself will be empty; causing a mismatch.

This can be undesirable. Sometimes you only want to re-run the load functions, that's it, the $page.state being emptied could be an unpleasant side-effect.
If someone wants to clear the $page.state as well, they could do so by simply invoking pushState({}) right afterwards. There's no reason for invalidateAll to do that internally, while not allowing the developer to choose whether they want that or not.

Describe the proposed solution

Either change the default behavior (I suspect this wasn't actually thought through, but feel free to correct me), or if this was somehow intended, at least add an option to invalidate and invalidateAll that leaves decision about whether they want to preserve the page state or not up to the developer:

invalidateAll({
    preserveState: true
});

Alternatives considered

No workarounds I could come up with, at the moment. Which is a big bummer.

Importance

severe

Additional Information

No response

Activity

  1. added a commit that references this issue on Feb 5, 2026
    05a5aae
  2. added a commit that references this issue on Jul 10, 2026
    8293144
  3. teemingc commented on Jul 10, 2026

    @teemingc
    Member

    Closed by #16289

  4. added theissue type on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions