File tree Expand file tree Collapse file tree 4 files changed +51
-1
lines changed
src/compiler/phases/3-transform
tests/runtime-runes/samples/hmr-each-keyed-unshift Expand file tree Collapse file tree 4 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ function sort_const_tags(nodes, state) {
137
137
* @param {Compiler.SvelteNode[] } nodes
138
138
* @param {Compiler.SvelteNode[] } path
139
139
* @param {Compiler.Namespace } namespace
140
- * @param {TransformState } state
140
+ * @param {TransformState & { options: Compiler.ValidatedCompileOptions } } state
141
141
* @param {boolean } preserve_whitespace
142
142
* @param {boolean } preserve_comments
143
143
*/
@@ -279,6 +279,7 @@ export function clean_nodes(
279
279
trimmed . length === 1 &&
280
280
( ( first . type === 'RenderTag' && ! first . metadata . dynamic ) ||
281
281
( first . type === 'Component' &&
282
+ ! state . options . hmr &&
282
283
! first . attributes . some (
283
284
( attribute ) => attribute . type === 'Attribute' && attribute . name . startsWith ( '--' )
284
285
) ) ) ;
Original file line number Diff line number Diff line change
1
+ <p >child</p >
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 : `<button>unshift</button>` ,
6
+
7
+ compileOptions : {
8
+ dev : true ,
9
+ hmr : true
10
+ } ,
11
+
12
+ test ( { assert, target } ) {
13
+ const btn = target . querySelector ( 'button' ) ;
14
+
15
+ flushSync ( ( ) => btn ?. click ( ) ) ;
16
+ assert . htmlEqual (
17
+ target . innerHTML ,
18
+ `
19
+ <button>unshift</button>
20
+ <p>child</p>
21
+ `
22
+ ) ;
23
+
24
+ flushSync ( ( ) => btn ?. click ( ) ) ;
25
+ assert . htmlEqual (
26
+ target . innerHTML ,
27
+ `
28
+ <button>unshift</button>
29
+ <p>child</p>
30
+ <p>child</p>
31
+ `
32
+ ) ;
33
+ }
34
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import Child from ' ./Child.svelte' ;
3
+
4
+ let uid = 0 ;
5
+
6
+ /** @type {Array<{ id: number }>} */
7
+ let items = $state ([]);
8
+ </script >
9
+
10
+ <button onclick ={() => items .unshift ({ id: uid ++ })}>unshift</button >
11
+
12
+ {#each items as item (item .id )}
13
+ <Child />
14
+ {/each }
You can’t perform that action at this time.
0 commit comments