Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sharp-tires-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: support for `URLSearchParams.has(name, value)` overload
4 changes: 2 additions & 2 deletions packages/kit/src/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export function make_trackable(url, callback, search_params_callback, allow_hash
value: new Proxy(tracked.searchParams, {
get(obj, key) {
if (key === 'get' || key === 'getAll' || key === 'has') {
return (/**@type {string}*/ param) => {
return (/** @type {string} */ param, /** @type {string[]} */ ...rest) => {
search_params_callback(param);
return obj[key](param);
return obj[key](param, ...rest);
};
}

Expand Down
23 changes: 23 additions & 0 deletions packages/kit/src/utils/url.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,29 @@ describe('make_trackable', (test) => {
url.searchParams.entries();
assert.ok(tracked);
});

test('tracks search params when using has(name, value) overload', () => {
let tracked = false;
const tracked_search_params = new Set();
const url = make_trackable(
new URL('https://svelte.dev/docs/kit?foo=1&foo=2'),
() => {
tracked = true;
},
(search_param) => {
tracked_search_params.add(search_param);
}
);

// has(name, value) should track the param and return correct result
assert.equal(url.searchParams.has('foo', '1'), true);
assert.ok(!tracked);
assert.ok(tracked_search_params.has('foo'));

// value argument should be forwarded correctly (not just checking name existence)
assert.equal(url.searchParams.has('foo', '3'), false);
assert.ok(!tracked);
});
});

describe('disable_search', (test) => {
Expand Down
Loading