File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
packages/svelte/src/internal/client/reactivity Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -601,15 +601,32 @@ function flush_queued_effects(effects) {
601601 // If update_effect() has a flushSync() in it, we may have flushed another flush_queued_effects(),
602602 // which already handled this logic and did set eager_block_effects to null.
603603 if ( eager_block_effects ?. length > 0 ) {
604- // TODO this feels incorrect! it gets the tests passing
605604 old_values . clear ( ) ;
606605
606+ /** @type {Array<{ effect: Effect; depth: number }> } */
607+ const effects_with_depth = [ ] ;
607608 for ( const e of eager_block_effects ) {
608- update_effect ( e ) ;
609+ // Skip eager effects that have already been unmounted
610+ if ( ( e . f & ( DESTROYED | INERT ) ) !== 0 ) continue ;
611+
612+ let depth = 0 ;
613+ let ancestor = e . parent ;
614+ while ( ancestor !== null ) {
615+ depth ++ ;
616+ ancestor = ancestor . parent ;
617+ }
618+
619+ effects_with_depth . push ( { effect : e , depth } ) ;
609620 }
610621
611- eager_block_effects = [ ] ;
622+ effects_with_depth . sort ( ( a , b ) => a . depth - b . depth ) ;
623+
624+ for ( const { effect } of effects_with_depth ) {
625+ update_effect ( effect ) ;
626+ }
612627 }
628+
629+ eager_block_effects = [ ] ;
613630 }
614631 }
615632
You can’t perform that action at this time.
0 commit comments