@@ -25,6 +25,7 @@ import {
25
25
import { source , mutable_source , set } from '../../reactivity/sources.js' ;
26
26
import { is_array , is_frozen } from '../../utils.js' ;
27
27
import { STATE_SYMBOL } from '../../constants.js' ;
28
+ import { push_template_node } from '../template.js' ;
28
29
29
30
/**
30
31
* The row of a keyed each block that is currently updating. We track this
@@ -168,10 +169,11 @@ export function each(anchor, flags, get_collection, get_key, render_fn, fallback
168
169
break ;
169
170
}
170
171
172
+ var child_open = /** @type {Comment } */ ( child_anchor ) ;
171
173
child_anchor = hydrate_anchor ( child_anchor ) ;
172
174
var value = array [ i ] ;
173
175
var key = get_key ( value , i ) ;
174
- item = create_item ( child_anchor , prev , null , value , key , i , render_fn , flags ) ;
176
+ item = create_item ( child_open , child_anchor , prev , null , value , key , i , render_fn , flags ) ;
175
177
state . items . set ( key , item ) ;
176
178
child_anchor = /** @type {Comment } */ ( child_anchor . nextSibling ) ;
177
179
@@ -278,8 +280,14 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
278
280
item = items . get ( key ) ;
279
281
280
282
if ( item === undefined ) {
283
+ var child_open = /** @type {Text } */ ( push_template_node ( empty ( ) ) ) ;
284
+ var child_anchor = current ? current . o : anchor ;
285
+
286
+ child_anchor . before ( child_open ) ;
287
+
281
288
prev = create_item (
282
- current ? get_first_child ( current ) : anchor ,
289
+ child_open ,
290
+ child_anchor ,
283
291
prev ,
284
292
prev . next ,
285
293
value ,
@@ -309,7 +317,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
309
317
if ( matched . length < stashed . length ) {
310
318
// more efficient to move later items to the front
311
319
var start = stashed [ 0 ] ;
312
- var local_anchor = get_first_child ( start ) ;
320
+ var local_anchor = start . o ;
313
321
var j ;
314
322
315
323
prev = start . prev ;
@@ -338,7 +346,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
338
346
} else {
339
347
// more efficient to move earlier items to the back
340
348
seen . delete ( item ) ;
341
- move ( item , current ? get_first_child ( current ) : anchor ) ;
349
+ move ( item , current ? current . o : anchor ) ;
342
350
343
351
link ( item . prev , item . next ) ;
344
352
link ( item , prev . next ) ;
@@ -399,20 +407,6 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
399
407
}
400
408
}
401
409
402
- /**
403
- * @param {import('#client').EachItem } item
404
- * @returns {Text | Element | Comment }
405
- */
406
- function get_first_child ( item ) {
407
- var current = item . e . dom ;
408
-
409
- if ( is_array ( current ) ) {
410
- return /** @type {Text | Element | Comment } */ ( current [ 0 ] ) ;
411
- }
412
-
413
- return /** @type {Text | Element | Comment } */ ( current ) ;
414
- }
415
-
416
410
/**
417
411
* @param {import('#client').EachItem } item
418
412
* @param {any } value
@@ -434,6 +428,7 @@ function update_item(item, value, index, type) {
434
428
435
429
/**
436
430
* @template V
431
+ * @param {Comment | Text } open
437
432
* @param {Node } anchor
438
433
* @param {import('#client').EachItem | import('#client').EachState } prev
439
434
* @param {import('#client').EachItem | null } next
@@ -444,7 +439,7 @@ function update_item(item, value, index, type) {
444
439
* @param {number } flags
445
440
* @returns {import('#client').EachItem }
446
441
*/
447
- function create_item ( anchor , prev , next , value , key , index , render_fn , flags ) {
442
+ function create_item ( open , anchor , prev , next , value , key , index , render_fn , flags ) {
448
443
var previous_each_item = current_each_item ;
449
444
450
445
try {
@@ -462,6 +457,7 @@ function create_item(anchor, prev, next, value, key, index, render_fn, flags) {
462
457
a : null ,
463
458
// @ts -expect-error
464
459
e : null ,
460
+ o : open ,
465
461
prev,
466
462
next
467
463
} ;
@@ -483,6 +479,8 @@ function create_item(anchor, prev, next, value, key, index, render_fn, flags) {
483
479
* @param {Text | Element | Comment } anchor
484
480
*/
485
481
function move ( item , anchor ) {
482
+ anchor . before ( item . o ) ;
483
+
486
484
var dom = item . e . dom ;
487
485
488
486
if ( dom !== null ) {
0 commit comments