File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
src/internal/client/dom/blocks
tests/runtime-legacy/samples/keyed-each-prod-unique-2 Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -370,6 +370,7 @@ function reconcile(
370
370
var is_animated = ( flags & EACH_IS_ANIMATED ) !== 0 ;
371
371
var should_update = ( flags & ( EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE ) ) !== 0 ;
372
372
373
+ var count = 0 ;
373
374
var length = array . length ;
374
375
var items = state . items ;
375
376
var first = state . first ;
@@ -458,6 +459,7 @@ function reconcile(
458
459
stashed = [ ] ;
459
460
460
461
current = prev . next ;
462
+ count += 1 ;
461
463
continue ;
462
464
}
463
465
@@ -519,6 +521,7 @@ function reconcile(
519
521
link ( state , prev , item ) ;
520
522
521
523
prev = item ;
524
+ count += 1 ;
522
525
}
523
526
524
527
continue ;
@@ -547,6 +550,14 @@ function reconcile(
547
550
matched . push ( item ) ;
548
551
prev = item ;
549
552
current = item . next ;
553
+ count += 1 ;
554
+ }
555
+
556
+ if ( count !== length ) {
557
+ // full key uniqueness check is dev-only,
558
+ // if keys duplication didn't cause a crash,
559
+ // the rendered list will be shorter then the array
560
+ each_key_duplicate ( '' , '' , '' ) ;
550
561
}
551
562
552
563
if ( current !== null || seen !== undefined ) {
Original file line number Diff line number Diff line change
1
+ import { flushSync } from 'svelte' ;
2
+ import { test } from '../../test' ;
3
+
4
+ export default test ( {
5
+ compileOptions : {
6
+ dev : false
7
+ } ,
8
+ test ( { assert, target } ) {
9
+ let button = target . querySelector ( 'button' ) ;
10
+
11
+ button ?. click ( ) ;
12
+
13
+ assert . throws ( flushSync , / e a c h _ k e y _ d u p l i c a t e / ) ;
14
+ }
15
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ let data = [1 , 2 , 3 ];
3
+ </script >
4
+
5
+ <button onclick ={() => data = [1 , 1 , 1 ]}>add</button >
6
+ {#each data as d (d )}
7
+ {d }
8
+ {/each }
You can’t perform that action at this time.
0 commit comments