Skip to content

Only read search params in the schema when validating a URL - #707

Open
dodoshell wants to merge 1 commit into
ciscoheat:mainfrom
dodoshell:fix-706-search-params-tracking
Open

dodoshell wants to merge 1 commit into
ciscoheat:mainfrom
dodoshell:fix-706-search-params-tracking

Conversation

@dodoshell

Copy link
Copy Markdown

Fixes #706

parseSearchParams copied every search param into a FormData with data.entries(). SvelteKit tracks entries() on url.searchParams as reading all params, so a load function calling superValidate(url, ...) reran whenever any param changed, also ones that aren't in the schema.

It now reads only the keys the schema knows with getAll: the schema properties, the properties of all union variants, plus __superform_id and __superform_json. The key list is the one _parseFormData already built, which I moved into a small formDataKeys helper so both use it. With strict: true, or a schema with additionalProperties, every param can end up in the data, so those cases still read all params like before.

Added src/tests/issue-706.test.ts, which uses a URLSearchParams subclass that records reads the way SvelteKit tracks them (get/getAll/has per key, iteration as all keys). The tests check that params outside the schema aren't read, for a plain object and a discriminated union, that the form id is still read, and that the parsed data is the same as with a plain URLSearchParams. All three fail on main and pass with the change.

pnpm test (446 passed), pnpm check and pnpm lint are clean. I added an [Unreleased] entry to the changelog as AGENTS.md asks; feel free to drop or reword it.

@vercel

vercel Bot commented Nov 13, 2026

Copy link
Copy Markdown

@dodoshell is attempting to deploy a commit to the Andreas Sderlund's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

superValidate(url) causes unnecessary SvelteKit load reruns by tracking unrelated search parameters

1 participant