kit icon indicating copy to clipboard operation
kit copied to clipboard

breaking: make `page.url` fine-grained with `SvelteURL`

Open Nic-Polumeyv opened this issue 5 months ago • 0 comments

[!NOTE] Depends on sveltejs/svelte#18425. The red CI is a single test repeated across jobs, it renders query params with searchParams.forEach, and forEach turns out to be the one read method SvelteURLSearchParams never overrides, so it tracks nothing. The coarse identity signal this PR removes was masking that gap. Kit's own suite catching an upstream reactivity bug is the dependency proving itself.

Implements the SvelteURL direction from #13746 (full reasoning in https://github.com/sveltejs/kit/issues/13746#issuecomment-4691715103). This is the reads-only first slice, the writable half has open design questions in that comment.

page.url becomes a stable SvelteURL behind a getter/setter, so the router's plain-URL assignments keep working untouched while reads become fine-grained:

$effect(() => page.url.pathname); // no longer wakes up when only ?q= changes
$effect(() => page.url.search);   // no longer wakes up when only the pathname changes
$effect(() => page.url);          // never fires again. this is the breaking change

That third line is why this targets version-3. Today url is $state.raw and replaced wholesale per navigation, so identity-based effects fire on every navigation and would silently stop here. It also couldn't have been built earlier, kit 2.x supports Svelte 4 where svelte/reactivity doesn't exist and state.svelte.js loads unconditionally, so the ^5.48.0 floor on this branch is what unlocks it.

A pleasant side effect, current.url = page.url = url now leaves the router's internal current.url as a plain URL instead of sharing one mutable object with userland, which removes half of the desync footgun described in #13746.

Known boundary, searchParams reads stay navigation-coarse until sveltejs/svelte#18425 lands, which fixes both the forEach gap above and the unconditional version bump behind sveltejs/svelte#17218.

The new state/url-fine-grained test asserts the exact rerun counts above and fails on version-3 without the source change. Existing page.url tests, including page.url can safely be mutated and the $app/stores ones, pass in dev and build. Type generation produces no diff, the public url: URL surface is unchanged.


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.

Nic-Polumeyv avatar Jun 12 '26 13:06 Nic-Polumeyv