@@ -33,11 +33,12 @@ import {
3333} from '../../reactivity/effects.js' ;
3434import { source , mutable_source , internal_set } from '../../reactivity/sources.js' ;
3535import { array_from , is_array } from '../../../shared/utils.js' ;
36- import { INERT } from '../../constants.js' ;
36+ import { FORK_ROOT , INERT } from '../../constants.js' ;
3737import { queue_micro_task } from '../task.js' ;
3838import { active_effect , active_reaction , get } from '../../runtime.js' ;
3939import { DEV } from 'esm-env' ;
4040import { derived_safe_equal } from '../../reactivity/deriveds.js' ;
41+ import { active_fork } from '../../fork.js' ;
4142
4243/**
4344 * The row of a keyed each block that is currently updating. We track this
@@ -453,19 +454,27 @@ function reconcile(array, state, anchor, render_fn, flags, is_inert, get_key, ge
453454 var destroy_length = to_destroy . length ;
454455
455456 if ( destroy_length > 0 ) {
456- var controlled_anchor = ( flags & EACH_IS_CONTROLLED ) !== 0 && length === 0 ? anchor : null ;
457+ function destroy ( ) {
458+ var controlled_anchor = ( flags & EACH_IS_CONTROLLED ) !== 0 && length === 0 ? anchor : null ;
457459
458- if ( is_animated ) {
459- for ( i = 0 ; i < destroy_length ; i += 1 ) {
460- to_destroy [ i ] . a ?. measure ( ) ;
461- }
460+ if ( is_animated ) {
461+ for ( i = 0 ; i < destroy_length ; i += 1 ) {
462+ to_destroy [ i ] . a ?. measure ( ) ;
463+ }
462464
463- for ( i = 0 ; i < destroy_length ; i += 1 ) {
464- to_destroy [ i ] . a ?. fix ( ) ;
465+ for ( i = 0 ; i < destroy_length ; i += 1 ) {
466+ to_destroy [ i ] . a ?. fix ( ) ;
467+ }
465468 }
469+
470+ pause_effects ( state , to_destroy , controlled_anchor , items ) ;
466471 }
467472
468- pause_effects ( state , to_destroy , controlled_anchor , items ) ;
473+ if ( active_fork !== null ) {
474+ active_fork . branches . push ( destroy ) ;
475+ } else {
476+ destroy ( ) ;
477+ }
469478 }
470479 }
471480
@@ -559,6 +568,20 @@ function create_item(
559568 current_each_item = item ;
560569
561570 try {
571+ if ( active_fork !== null && ( active_fork . f & FORK_ROOT ) !== 0 ) {
572+ active_fork . f ^= FORK_ROOT ;
573+
574+ const onscreen_anchor = anchor ;
575+
576+ const fragment = document . createDocumentFragment ( ) ;
577+ anchor = document . createComment ( '' ) ;
578+ fragment . append ( anchor ) ;
579+
580+ active_fork . branches . push ( ( ) => {
581+ onscreen_anchor . before ( fragment ) ;
582+ } ) ;
583+ }
584+
562585 item . e = branch ( ( ) => render_fn ( anchor , v , i , get_collection ) , hydrating ) ;
563586
564587 item . e . prev = prev && prev . e ;
@@ -578,6 +601,10 @@ function create_item(
578601
579602 return item ;
580603 } finally {
604+ if ( active_fork !== null ) {
605+ active_fork . f |= FORK_ROOT ;
606+ }
607+
581608 current_each_item = previous_each_item ;
582609 }
583610}
0 commit comments