Skip to content

Conversation

@RoryDuncan
Copy link

@RoryDuncan RoryDuncan commented Dec 19, 2025

The proxied URLSearchParams does not support the value parameter of the has method. Signature being has(name, value). You can see the first parameter—param—being the only forwarded argument in packages/kit/src/utils/url.js.

SvelteKit's URLSearchParams shares the same interface as mdn's URLSearchParams but its implementation differs.

As an example: Within a layout or page load function where a request has the url http://localhost:5173/?features=test.

export const load: LayoutLoad = ({ url }) => {
   url.searchParams.has("features"); // true
   url.searchParams.has("features", "test"); // true
   url.searchParams.has("features", "banners"); // true, incorrectly
   url.searchParams.has("features", "nonsense"); // true, incorrectly
   
   const searchParams = new URLSearchParams(url.href);
   searchParams.has("features"); // true
   searchParams.has("features", "test"); // true
   searchParams.has("features", "banners"); // false
   searchParams.has("features", "nonsense"); // false

   ...
}

Workaround

Creating a new URLSearchParams via the loader's url is a work-around.

Fix

Passing additional params in the proxy solves the issue.

  1. In my changes, I'm uncertain if the search_params_callback signature should be changed to optionally have the value.
  2. While the tests verify the changes work I am uncertain that adding a test for adherence to the browser interfaces is setting precedent for similar tests, and if that is out of intended scope for sveltekit's maintainers.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • 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

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link

changeset-bot bot commented Dec 19, 2025

🦋 Changeset detected

Latest commit: 38d4ab5

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

@RoryDuncan
Copy link
Author

Adding the changeset...

@elliott-with-the-longest-name-on-github
Copy link
Contributor

TIL this API exists 😆 Thanks! I'll rebase you on main after my fixes for the timing-out tests merges, then this should be good to go

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.

2 participants