fix: allow shallow routing during initial render#16338
Closed
Nic-Polumeyv wants to merge 1 commit into
Closed
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/3718f4a45d15de3a62aac5f4ed742a0deb17d36eOpen in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: 3718f4a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Contributor
Author
|
This overlaps with #16307 on the |
Nic-Polumeyv
force-pushed
the
fix-shallow-routing-initial-effect
branch
from
July 15, 2026 01:07
3a2bec5 to
4f79e29
Compare
Nic-Polumeyv
force-pushed
the
fix-shallow-routing-initial-effect
branch
from
July 15, 2026 01:59
4f79e29 to
3718f4a
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #15927
Calling
replaceStateorpushStateinside a top-level$effectthrowsCannot call replaceState(...) before router is initializedin dev, even though everything shallow routing needs already exists at that point.Twas the release before Svelte 5, and
onMountstill ran before the router existed, so calling these functions there crashed onroot.$set(#11466). #11968 wrapped that crash in a readable dev error, on the reasoning that Svelte 5 had made the problem unreachable sinceonMountnow runs after initial render. That was right aboutonMountand wrong about$effect, which flushes while the root component is still being created. Everything shallow routing needs already exists in that window,pageand the history indexes. So the dev error no longer means what it says.Two changes.
router_initializedflag that flips right before the root component is created, once everything shallow routing needs is in place. Genuinely-too-early calls, from module scope orload, throw the same error as before.page.url.hrefread inside both functions is tracked, so any effect calling them silently depends onpage.url, and going back to a pushed entry re-ran the effect, which re-pushed the state it had just left. fix: prevent infinite loop when callingpushState/replaceStatein effect #13914 fixed this class forclone_page, this read escaped it. It's untracked now.startedis untouched, it also gates initial fetch handling,navigatingand scroll behavior.An earlier revision targeted
main, where the stakes are higher: kit 2'spushState/replaceStatestill callroot.$setfor the legacy stores, so the same call crashes production withTypeError: Cannot read properties of undefined (reading '$set'). That part of the fix (falling back to the store whilerootdoesn't exist yet) has no equivalent here since the stores are gone (#15499). If a 2.x patch is wanted I can reopen that version againstmain.The new tests fail on
version-3without the fix. In dev both hit the guard, in build the pushState test catches the effect re-run.Overlaps with #16307 on the
PAGE_URL_KEYlines. Whichever merges second, keepresolve_url(url).hrefand drop theuntrack, sinceresolve_urlnever had the reactive dependency.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
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