Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: emit each_key_duplicate error in production #16724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
7nik wants to merge 11 commits into main
base: main
Choose a base branch
Loading
from fix-15339
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix: emit each_key_duplicate error in production
  • Loading branch information
7nik committed Sep 6, 2025
commit ec016eb253191df1c14ce75005683e3616bd0bcb
5 changes: 5 additions & 0 deletions .changeset/sharp-snakes-poke.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: emit `each_key_duplicate` error in production
16 changes: 16 additions & 0 deletions packages/svelte/src/internal/client/dom/blocks/each.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { active_effect, get } from '../../runtime.js';
import { DEV } from 'esm-env';
import { derived_safe_equal } from '../../reactivity/deriveds.js';
import { current_batch } from '../../reactivity/batch.js';
import { each_key_duplicate } from '../../errors.js';

/**
* The row of a keyed each block that is currently updating. We track this
Expand Down Expand Up @@ -473,6 +474,21 @@ function reconcile(
var start = stashed[0];
var j;

// full key uniqueness check is dev-only,
// key duplicates cause crushing only due to `matched` being empty
if (matched.length === 0) {
var map = new Map();
for (j = 0; j < length; j += 1) {
var k = get_key(array[j], j);
if (map.has(k)) {
k = String(k);
if (k.startsWith('[object ')) k = null;
each_key_duplicate(String(j), String(map.get(k)), k);
}
map.set(k, j);
}
}

prev = start.prev;

var a = matched[0];
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
test({ assert, target }) {
let button = target.querySelector('button');

button?.click();

assert.throws(flushSync, /each_key_duplicate/);
}
});
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
let data = [1, 2, 3];
</script>

<button onclick={() => data = [1, 1, 3, 1]}>add</button>
{#each data as d (d)}
{d}
{/each}
Loading

AltStyle によって変換されたページ (->オリジナル) /