File tree Expand file tree Collapse file tree 5 files changed +99
-5
lines changed
tests/runtime-runes/samples/each-updates Expand file tree Collapse file tree 5 files changed +99
-5
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: improve key block reactivity detection
Original file line number Diff line number Diff line change 1
1
export const EACH_ITEM_REACTIVE = 1 ;
2
2
export const EACH_INDEX_REACTIVE = 1 << 1 ;
3
3
export const EACH_KEYED = 1 << 2 ;
4
+ export const EACH_PROXIED = 1 << 3 ;
4
5
export const EACH_IS_CONTROLLED = 1 << 3 ;
5
6
export const EACH_IS_ANIMATED = 1 << 4 ;
6
7
export const EACH_IS_IMMUTABLE = 1 << 6 ;
Original file line number Diff line number Diff line change @@ -351,13 +351,8 @@ function reconcile_tracked_array(
351
351
) {
352
352
var a_blocks = each_block . v ;
353
353
const is_computed_key = keys !== null ;
354
- var is_proxied_array = STATE_SYMBOL in array && /** @type {any } */ ( array [ STATE_SYMBOL ] ) . i ;
355
354
var active_transitions = each_block . s ;
356
355
357
- if ( is_proxied_array ) {
358
- flags &= ~ EACH_ITEM_REACTIVE ;
359
- }
360
-
361
356
/** @type {number | void } */
362
357
var a = a_blocks . length ;
363
358
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 : `<p>test costs $1</p><p>test 2 costs $2</p><p>test costs $1</p><p>test 2 costs $2</p><button>add</button><button>change</button><button>reload</button>` ,
6
+ skip_if_ssr : 'permanent' ,
7
+ skip_if_hydrate : 'permanent' ,
8
+
9
+ async test ( { assert, target } ) {
10
+ const [ btn1 , btn2 , btn3 ] = target . querySelectorAll ( 'button' ) ;
11
+
12
+ flushSync ( ( ) => {
13
+ btn2 . click ( ) ;
14
+ } ) ;
15
+
16
+ assert . htmlEqual (
17
+ target . innerHTML ,
18
+ `<p>test costs $1</p><p>test 2 costs $2000</p><p>test costs $1</p><p>test 2 costs $2000</p><button>add</button><button>change</button><button>reload</button>`
19
+ ) ;
20
+
21
+ flushSync ( ( ) => {
22
+ btn1 . click ( ) ;
23
+ } ) ;
24
+
25
+ assert . htmlEqual (
26
+ target . innerHTML ,
27
+ `<p>test costs $1</p><p>test 2 costs $2000</p><p>test 3 costs $3</p><p>test costs $1</p><p>test 2 costs $2000</p><p>test 3 costs $3</p><button>add</button><button>change</button><button>reload</button>`
28
+ ) ;
29
+
30
+ flushSync ( ( ) => {
31
+ btn3 . click ( ) ;
32
+ } ) ;
33
+
34
+ assert . htmlEqual (
35
+ target . innerHTML ,
36
+ `<p>test costs $1</p><p>test 2 costs $2000</p><p>test costs $1</p><p>test 2 costs $2000</p><button>add</button><button>change</button><button>reload</button>`
37
+ ) ;
38
+ }
39
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ let data = $state ({ items: [] });
3
+
4
+ function fetchData () {
5
+ data = {
6
+ items: [{
7
+ id: 1 ,
8
+ price: 1 ,
9
+ name: ' test'
10
+ }, {
11
+ id: 2 ,
12
+ price: 2 ,
13
+ name: ' test 2'
14
+ }]
15
+ };
16
+ }
17
+
18
+ fetchData ();
19
+
20
+ function copyItems (original ) {
21
+ return [... original .map ((item ) => ({ ... item }))];
22
+ }
23
+
24
+ let items = $state ();
25
+
26
+ $effect (() => {
27
+ items = copyItems (data .items );
28
+ });
29
+ </script >
30
+
31
+ {#each items as item }
32
+ <p >{item .name } costs ${item .price }</p >
33
+ {/each }
34
+
35
+ {#each items as item (item .id )}
36
+ <p >{item .name } costs ${item .price }</p >
37
+ {/each }
38
+
39
+
40
+ <button onclick ={() => {
41
+ items .push ({
42
+ id: 3 ,
43
+ price: 3 ,
44
+ name: ' test 3'
45
+ })
46
+ }}>add</button >
47
+
48
+ <button onclick ={() => {
49
+ data .items [1 ].price = 2000
50
+ }}>change</button >
51
+
52
+ <button onclick ={() => {
53
+ fetchData ();
54
+ }}>reload</button >
You can’t perform that action at this time.
0 commit comments