Skip to content

Conversation

@FrankFMY
Copy link
Contributor

@FrankFMY FrankFMY commented Feb 5, 2026

Summary

$page.state (shallow routing state set via pushState/replaceState) was incorrectly being cleared whenever invalidate() or invalidateAll() was called. These functions are meant to re-run load functions, not affect navigation state.

Root cause

The internal _invalidate() function defaulted to reset_page_state = true, which causes the state to be wiped after load_route() creates a new page object with state: {}. Meanwhile, refreshAll() already correctly passes reset_page_state = false.

Fix

Changed the default parameter from reset_page_state = true to reset_page_state = false, so invalidate() and invalidateAll() preserve the existing $page.state — consistent with refreshAll().

Fixes #11783

Test plan

  • Added test "Preserves page state when invalidating" — sets state via pushState, calls invalidateAll, verifies state is preserved and load function re-ran
  • All 34 existing invalidation tests pass
  • All 31 existing state-related tests pass
  • All 10 shallow routing tests pass
  • All 417 unit tests pass

The _invalidate function defaulted to reset_page_state=true, which
caused $page.state (shallow routing state) to be cleared whenever
invalidate() or invalidateAll() was called. This was unexpected since
these functions are meant to re-run load functions, not affect
navigation state.

Changed the default to false, matching the behavior already used by
refreshAll(). Added a test verifying state persistence across
invalidation.

Fixes sveltejs#11783
@changeset-bot
Copy link

changeset-bot bot commented Feb 5, 2026

🦋 Changeset detected

Latest commit: 05a5aae

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

@svelte-docs-bot
Copy link

@PatrickG
Copy link
Member

PatrickG commented Feb 6, 2026

#11810?

@FrankFMY
Copy link
Contributor Author

FrankFMY commented Feb 6, 2026

Oh, I missed your existing PR — sorry about the duplicate! Closing in favor of #11810.

@FrankFMY FrankFMY closed this Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$page.state is cleared when invalidate is invoked

2 participants