@@ -25,6 +25,7 @@ import {
2525import { source , mutable_source , set } from '../../reactivity/sources.js' ;
2626import { is_array , is_frozen } from '../../utils.js' ;
2727import { INERT , STATE_SYMBOL } from '../../constants.js' ;
28+ import { push_template_node } from '../template.js' ;
2829
2930/**
3031 * 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
168169 break ;
169170 }
170171
172+ var child_open = /** @type {Comment } */ ( child_anchor ) ;
171173 child_anchor = hydrate_anchor ( child_anchor ) ;
172174 var value = array [ i ] ;
173175 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 ) ;
175177 state . items . set ( key , item ) ;
176178 child_anchor = /** @type {Comment } */ ( child_anchor . nextSibling ) ;
177179
@@ -278,8 +280,14 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
278280 item = items . get ( key ) ;
279281
280282 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+
281288 prev = create_item (
282- current ? get_first_child ( current ) : anchor ,
289+ child_open ,
290+ child_anchor ,
283291 prev ,
284292 prev . next ,
285293 value ,
@@ -312,7 +320,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
312320 if ( matched . length < stashed . length ) {
313321 // more efficient to move later items to the front
314322 var start = stashed [ 0 ] ;
315- var local_anchor = get_first_child ( start ) ;
323+ var local_anchor = start . o ;
316324 var j ;
317325
318326 prev = start . prev ;
@@ -341,7 +349,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
341349 } else {
342350 // more efficient to move earlier items to the back
343351 seen . delete ( item ) ;
344- move ( item , current ? get_first_child ( current ) : anchor ) ;
352+ move ( item , current ? current . o : anchor ) ;
345353
346354 link ( item . prev , item . next ) ;
347355 link ( item , prev . next ) ;
@@ -402,20 +410,6 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
402410 }
403411}
404412
405- /**
406- * @param {import('#client').EachItem } item
407- * @returns {Text | Element | Comment }
408- */
409- function get_first_child ( item ) {
410- var current = item . e . dom ;
411-
412- if ( is_array ( current ) ) {
413- return /** @type {Text | Element | Comment } */ ( current [ 0 ] ) ;
414- }
415-
416- return /** @type {Text | Element | Comment } */ ( current ) ;
417- }
418-
419413/**
420414 * @param {import('#client').EachItem } item
421415 * @param {any } value
@@ -437,6 +431,7 @@ function update_item(item, value, index, type) {
437431
438432/**
439433 * @template V
434+ * @param {Comment | Text } open
440435 * @param {Node } anchor
441436 * @param {import('#client').EachItem | import('#client').EachState } prev
442437 * @param {import('#client').EachItem | null } next
@@ -447,7 +442,7 @@ function update_item(item, value, index, type) {
447442 * @param {number } flags
448443 * @returns {import('#client').EachItem }
449444 */
450- function create_item ( anchor , prev , next , value , key , index , render_fn , flags ) {
445+ function create_item ( open , anchor , prev , next , value , key , index , render_fn , flags ) {
451446 var previous_each_item = current_each_item ;
452447
453448 try {
@@ -465,6 +460,7 @@ function create_item(anchor, prev, next, value, key, index, render_fn, flags) {
465460 a : null ,
466461 // @ts -expect-error
467462 e : null ,
463+ o : open ,
468464 prev,
469465 next
470466 } ;
@@ -486,6 +482,8 @@ function create_item(anchor, prev, next, value, key, index, render_fn, flags) {
486482 * @param {Text | Element | Comment } anchor
487483 */
488484function move ( item , anchor ) {
485+ anchor . before ( item . o ) ;
486+
489487 var dom = item . e . dom ;
490488
491489 if ( dom !== null ) {
0 commit comments