File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
packages/svelte/src/internal/client/reactivity Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -626,9 +626,28 @@ function flush_queued_effects(effects) {
626626 // TODO this feels incorrect! it gets the tests passing
627627 old_values . clear ( ) ;
628628
629+ /**
630+ * @type {Array<{ effect: Effect; depth: number }> } sorted
631+ */
632+ const sorted = Array ( eager_block_effects . length ) ;
633+ for ( let j = 0 ; j < eager_block_effects . length ; j ++ ) {
634+ var depth = 0 ;
635+ var parent = eager_block_effects [ j ] . parent ;
636+
637+ while ( parent !== null ) {
638+ depth ++ ;
639+ parent = parent . parent ;
640+ }
641+
642+ sorted [ j ] = { effect : eager_block_effects [ j ] , depth } ;
643+ }
644+
645+ // Sort by depth
646+ sorted . sort ( ( a , b ) => a . depth - b . depth ) ;
647+
629648 // Update effects in reverse order to ensure outer guards are processed before their contents
630- for ( let i = eager_block_effects . length - 1 ; i >= 0 ; i -- ) {
631- update_effect ( eager_block_effects [ i ] ) ;
649+ for ( const e of sorted ) {
650+ update_effect ( e . effect ) ;
632651 }
633652
634653 eager_block_effects = [ ] ;
You can’t perform that action at this time.
0 commit comments