fix: cover other case of duplicate keys

fix-15339
7nik 3 days ago
parent c208ef00a0
commit cb89bb8a6b

@ -370,6 +370,7 @@ function reconcile(
var is_animated = (flags & EACH_IS_ANIMATED) !== 0;
var should_update = (flags & (EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE)) !== 0;
var count = 0;
var length = array.length;
var items = state.items;
var first = state.first;
@ -458,6 +459,7 @@ function reconcile(
stashed = [];
current = prev.next;
count += 1;
continue;
}
@ -519,6 +521,7 @@ function reconcile(
link(state, prev, item);
prev = item;
count += 1;
}
continue;
@ -547,6 +550,14 @@ function reconcile(
matched.push(item);
prev = item;
current = item.next;
count += 1;
}
if (count !== length) {
// full key uniqueness check is dev-only,
// if keys duplication didn't cause a crash,
// the rendered list will be shorter then the array
each_key_duplicate('', '', '');
}
if (current !== null || seen !== undefined) {

@ -0,0 +1,15 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
compileOptions: {
dev: false
},
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, 1]}>add</button>
{#each data as d (d)}
{d}
{/each}
Loading…
Cancel
Save