File tree Expand file tree Collapse file tree 4 files changed +53
-1
lines changed
src/internal/client/dom/blocks
tests/runtime-runes/samples/each-updates-5 Expand file tree Collapse file tree 4 files changed +53
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " svelte " : patch
3
+ ---
4
+
5
+ fix: improve indexed each equality
Original file line number Diff line number Diff line change @@ -332,6 +332,11 @@ function reconcile_indexed_array(
332
332
flags ,
333
333
apply_transitions
334
334
) {
335
+ // If we are working with an array that isn't proxied or frozen, then remove strict equality and ensure the items
336
+ // are treated as reactive, so they get wrapped in a signal.
337
+ if ( ( flags & EACH_IS_STRICT_EQUALS ) !== 0 && ! is_frozen ( array ) && ! ( STATE_SYMBOL in array ) ) {
338
+ flags ^= EACH_IS_STRICT_EQUALS ;
339
+ }
335
340
var a_blocks = each_block . v ;
336
341
var active_transitions = each_block . s ;
337
342
@@ -449,7 +454,8 @@ function reconcile_tracked_array(
449
454
apply_transitions ,
450
455
keys
451
456
) {
452
- // If we are working with an array that isn't proxied or frozen, then remove strict equality.
457
+ // If we are working with an array that isn't proxied or frozen, then remove strict equality and ensure the items
458
+ // are treated as reactive, so they get wrapped in a signal.
453
459
if ( ( flags & EACH_IS_STRICT_EQUALS ) !== 0 && ! is_frozen ( array ) && ! ( STATE_SYMBOL in array ) ) {
454
460
flags ^= EACH_IS_STRICT_EQUALS ;
455
461
}
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
+ html : `1\n1\n<button>+</button>` ,
6
+
7
+ async test ( { assert, target } ) {
8
+ /**
9
+ * @type {{ click: () => void; } }
10
+ */
11
+ let btn1 ;
12
+
13
+ [ btn1 ] = target . querySelectorAll ( 'button' ) ;
14
+
15
+ flushSync ( ( ) => {
16
+ btn1 . click ( ) ;
17
+ } ) ;
18
+
19
+ assert . htmlEqual ( target . innerHTML , `2\n2\n<button>+</button>` ) ;
20
+ }
21
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import { writable } from " svelte/store" ;
3
+
4
+ let store = writable ([{ value: 1 }]);
5
+ let storeDeeper = writable ({ items: [{ value: 1 }] });
6
+
7
+ function increment () {
8
+ $store[0 ].value ++ ;
9
+ $storeDeeper .items [0 ].value ++ ;
10
+ }
11
+ </script >
12
+
13
+ {#each $store as item }
14
+ {item .value }
15
+ {/each }
16
+ {#each $storeDeeper .items as item }
17
+ {item .value }
18
+ {/each }
19
+
20
+ <button onclick ={increment }>+</button >
You can’t perform that action at this time.
0 commit comments