Skip to content

Fix searchParams.set duplicate updates#18336

Merged
Rich-Harris merged 5 commits into
sveltejs:mainfrom
jiyujie2006:fix-search-params-set-duplicates
May 31, 2026
Merged

Fix searchParams.set duplicate updates#18336
Rich-Harris merged 5 commits into
sveltejs:mainfrom
jiyujie2006:fix-search-params-set-duplicates

Conversation

@jiyujie2006

Copy link
Copy Markdown
Contributor

Summary

  • detect SvelteURLSearchParams#set changes by comparing duplicate value lists instead of joined strings
  • update reactive subscribers when duplicate params collapse to a single value with the same concatenated text
  • cover both SvelteURLSearchParams and SvelteURL.searchParams synchronization

Tests

  • pnpm exec vitest run packages/svelte/src/reactivity/url-search-params.test.ts -t "URLSearchParams.set updates when duplicate values collapse to the same joined string"
  • pnpm exec vitest run packages/svelte/src/reactivity/url-search-params.test.ts packages/svelte/src/reactivity/url.test.ts

@changeset-bot

changeset-bot Bot commented May 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a4f62cb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte 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

*/
set(name, value) {
var previous = super.getAll(name).join('');
var previous = super.getAll(name);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var previous = super.getAll(name);
var previous = super.getAll(name).join(',');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think keeping the element-wise comparison avoids another collision case: new URLSearchParams('a=a&a=b') followed by set('a', 'a,b') changes the query string to a=a%2Cb, but both sides of join(',') are a,b. I added a regression test for that case in cb2d87a.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, silly me — I thought the comma would be encoded in that case

Comment on lines +139 to +140
var current = super.getAll(name);
if (previous.length !== current.length || previous.some((value, i) => value !== current[i])) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var current = super.getAll(name);
if (previous.length !== current.length || previous.some((value, i) => value !== current[i])) {
if (previous !== super.getAll(name).join(',')) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern here: the comma-joined comparison would miss the a=a&a=b -> a=a%2Cb transition. The added test covers that edge case, so I kept the element-wise comparison.

Comment thread .changeset/search-params-duplicate-set.md Outdated

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — I think we can fix this more simply by just joining on "," instead of the empty string?

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@Rich-Harris Rich-Harris merged commit 2f6307a into sveltejs:main May 31, 2026
16 of 17 checks passed
@github-actions github-actions Bot mentioned this pull request May 31, 2026
Rich-Harris pushed a commit that referenced this pull request Jun 1, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## svelte@5.56.1

### Patch Changes

- fix: error at compile time on duplicate snippet/declaration tag
definitions ([#18351](#18351))

- fix: parse declaration tag contents more robustly
([#18353](#18353))

- fix: correctly transform references to earlier declarators in a
declaration tag (e.g. `{let a = $state(0), b = $derived(a * 2)}`)
([#18348](#18348))

- fix: avoid spurious `state_referenced_locally` warnings for `$derived`
declarations in declaration tags
([#18348](#18348))

- fix: tolerate whitespace before `let`/`const` in declaration tags
([#18348](#18348))

- fix: prevent infinite loop when a tag's expression ends with a
trailing `/` at the end of the input
([#18350](#18350))

- fix: more robust parsing of declaration tags with regards to `type`
([#18330](#18330))

- fix: preserve newlines in spread input values when the `type`
attribute is applied after `value`
([#18345](#18345))

- fix: update `SvelteURLSearchParams` when setting duplicate keys to the
same joined value
([#18336](#18336))

- fix: check references for blockers on server, too
([#18352](#18352))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
huskas-2189 added a commit to huskas-2189/Bookmark that referenced this pull request Jun 14, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [svelte](https://svelte.dev) ([source](https://github.com/sveltejs/svelte/tree/HEAD/packages/svelte)) | [`5.56.0` → `5.56.1`](https://renovatebot.com/diffs/npm/svelte/5.56.0/5.56.1) | ![age](https://developer.mend.io/api/mc/badges/age/npm/svelte/5.56.1?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/svelte/5.56.0/5.56.1?slim=true) |

---

### Release Notes

<details>
<summary>sveltejs/svelte (svelte)</summary>

### [`v5.56.1`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5561)

[Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.56.0...svelte@5.56.1)

##### Patch Changes

- fix: error at compile time on duplicate snippet/declaration tag definitions ([#&#8203;18351](sveltejs/svelte#18351))

- fix: parse declaration tag contents more robustly ([#&#8203;18353](sveltejs/svelte#18353))

- fix: correctly transform references to earlier declarators in a declaration tag (e.g. `{let a = $state(0), b = $derived(a * 2)}`) ([#&#8203;18348](sveltejs/svelte#18348))

- fix: avoid spurious `state_referenced_locally` warnings for `$derived` declarations in declaration tags ([#&#8203;18348](sveltejs/svelte#18348))

- fix: tolerate whitespace before `let`/`const` in declaration tags ([#&#8203;18348](sveltejs/svelte#18348))

- fix: prevent infinite loop when a tag's expression ends with a trailing `/` at the end of the input ([#&#8203;18350](sveltejs/svelte#18350))

- fix: more robust parsing of declaration tags with regards to `type` ([#&#8203;18330](sveltejs/svelte#18330))

- fix: preserve newlines in spread input values when the `type` attribute is applied after `value` ([#&#8203;18345](sveltejs/svelte#18345))

- fix: update `SvelteURLSearchParams` when setting duplicate keys to the same joined value ([#&#8203;18336](sveltejs/svelte#18336))

- fix: check references for blockers on server, too ([#&#8203;18352](sveltejs/svelte#18352))

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled because a matching PR was automerged previously.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xOTUuMCIsInVwZGF0ZWRJblZlciI6IjQzLjE5NS4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6W119-->

Co-authored-by: huskas-2189 <huskas-2189@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/huskas-2189/Bookmark/pulls/82
huskas-2189 added a commit to huskas-2189/Bookmark that referenced this pull request Jun 19, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [svelte](https://svelte.dev) ([source](https://github.com/sveltejs/svelte/tree/HEAD/packages/svelte)) | [`5.56.0` → `5.56.1`](https://renovatebot.com/diffs/npm/svelte/5.56.0/5.56.1) | ![age](https://developer.mend.io/api/mc/badges/age/npm/svelte/5.56.1?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/svelte/5.56.0/5.56.1?slim=true) |

---

### Release Notes

<details>
<summary>sveltejs/svelte (svelte)</summary>

### [`v5.56.1`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5561)

[Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.56.0...svelte@5.56.1)

##### Patch Changes

- fix: error at compile time on duplicate snippet/declaration tag definitions ([#&#8203;18351](sveltejs/svelte#18351))

- fix: parse declaration tag contents more robustly ([#&#8203;18353](sveltejs/svelte#18353))

- fix: correctly transform references to earlier declarators in a declaration tag (e.g. `{let a = $state(0), b = $derived(a * 2)}`) ([#&#8203;18348](sveltejs/svelte#18348))

- fix: avoid spurious `state_referenced_locally` warnings for `$derived` declarations in declaration tags ([#&#8203;18348](sveltejs/svelte#18348))

- fix: tolerate whitespace before `let`/`const` in declaration tags ([#&#8203;18348](sveltejs/svelte#18348))

- fix: prevent infinite loop when a tag's expression ends with a trailing `/` at the end of the input ([#&#8203;18350](sveltejs/svelte#18350))

- fix: more robust parsing of declaration tags with regards to `type` ([#&#8203;18330](sveltejs/svelte#18330))

- fix: preserve newlines in spread input values when the `type` attribute is applied after `value` ([#&#8203;18345](sveltejs/svelte#18345))

- fix: update `SvelteURLSearchParams` when setting duplicate keys to the same joined value ([#&#8203;18336](sveltejs/svelte#18336))

- fix: check references for blockers on server, too ([#&#8203;18352](sveltejs/svelte#18352))

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled because a matching PR was automerged previously.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xOTUuMCIsInVwZGF0ZWRJblZlciI6IjQzLjE5NS4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6W119-->

Co-authored-by: huskas-2189 <huskas-2189@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/huskas-2189/Bookmark/pulls/82
huskas-2189 added a commit to huskas-2189/Bookmark that referenced this pull request Jun 19, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [svelte](https://svelte.dev) ([source](https://github.com/sveltejs/svelte/tree/HEAD/packages/svelte)) | [`5.56.0` → `5.56.1`](https://renovatebot.com/diffs/npm/svelte/5.56.0/5.56.1) | ![age](https://developer.mend.io/api/mc/badges/age/npm/svelte/5.56.1?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/svelte/5.56.0/5.56.1?slim=true) |

---

### Release Notes

<details>
<summary>sveltejs/svelte (svelte)</summary>

### [`v5.56.1`](https://github.com/sveltejs/svelte/blob/HEAD/packages/svelte/CHANGELOG.md#5561)

[Compare Source](https://github.com/sveltejs/svelte/compare/svelte@5.56.0...svelte@5.56.1)

##### Patch Changes

- fix: error at compile time on duplicate snippet/declaration tag definitions ([#&#8203;18351](sveltejs/svelte#18351))

- fix: parse declaration tag contents more robustly ([#&#8203;18353](sveltejs/svelte#18353))

- fix: correctly transform references to earlier declarators in a declaration tag (e.g. `{let a = $state(0), b = $derived(a * 2)}`) ([#&#8203;18348](sveltejs/svelte#18348))

- fix: avoid spurious `state_referenced_locally` warnings for `$derived` declarations in declaration tags ([#&#8203;18348](sveltejs/svelte#18348))

- fix: tolerate whitespace before `let`/`const` in declaration tags ([#&#8203;18348](sveltejs/svelte#18348))

- fix: prevent infinite loop when a tag's expression ends with a trailing `/` at the end of the input ([#&#8203;18350](sveltejs/svelte#18350))

- fix: more robust parsing of declaration tags with regards to `type` ([#&#8203;18330](sveltejs/svelte#18330))

- fix: preserve newlines in spread input values when the `type` attribute is applied after `value` ([#&#8203;18345](sveltejs/svelte#18345))

- fix: update `SvelteURLSearchParams` when setting duplicate keys to the same joined value ([#&#8203;18336](sveltejs/svelte#18336))

- fix: check references for blockers on server, too ([#&#8203;18352](sveltejs/svelte#18352))

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled because a matching PR was automerged previously.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xOTUuMCIsInVwZGF0ZWRJblZlciI6IjQzLjE5NS4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6W119-->

Co-authored-by: huskas-2189 <huskas-2189@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/huskas-2189/Bookmark/pulls/82
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