fix: emit `each_key_duplicate` error in production

fix-15339
7nik 2 days ago
parent d92fa432d1
commit ec016eb253

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: emit `each_key_duplicate` error in production

@ -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
@ -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];

@ -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/);
}
});

@ -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…
Cancel
Save