@@ -683,11 +683,7 @@ function infinite_loop_guard() {
683683
684684function flush_queued_root_effects ( ) {
685685 var was_updating_effect = is_updating_effect ;
686-
687- // TODO it should be impossible to get here without an active fork
688- if ( ! active_fork && queued_root_effects . length > 0 ) {
689- console . trace ( 'here' ) ;
690- }
686+ var fork = /** @type {Fork } */ ( active_fork ) ;
691687
692688 try {
693689 var flush_count = 0 ;
@@ -698,7 +694,7 @@ function flush_queued_root_effects() {
698694 infinite_loop_guard ( ) ;
699695 }
700696
701- var revert = active_fork ? .apply ( ) ;
697+ var revert = fork . apply ( ) ;
702698
703699 /** @type {Effect[] } */
704700 var async_effects = [ ] ;
@@ -724,13 +720,13 @@ function flush_queued_root_effects() {
724720 process_effects ( root , async_effects , render_effects , effects ) ;
725721 }
726722
727- if ( async_effects . length === 0 && ( active_fork === null || active_fork . pending === 0 ) ) {
728- active_fork ? .commit ( ) ;
723+ if ( async_effects . length === 0 && fork . pending === 0 ) {
724+ fork . commit ( ) ;
729725 flush_queued_effects ( render_effects ) ;
730726 flush_queued_effects ( effects ) ;
731727 }
732728
733- revert ?. ( ) ;
729+ revert ( ) ;
734730
735731 for ( const effect of async_effects ) {
736732 update_effect ( effect ) ;
@@ -795,11 +791,13 @@ export function schedule_effect(signal) {
795791 if ( ! is_flushing ) {
796792 is_flushing = true ;
797793 queueMicrotask ( ( ) => {
794+ if ( active_fork === null ) {
795+ // a flushSync happened in the meantime
796+ return ;
797+ }
798+
798799 flush_queued_root_effects ( ) ;
799800
800- // TODO this doesn't seem quite right — may run into
801- // interesting cases where there are multiple roots.
802- // it'll do for now though
803801 if ( active_fork ?. pending === 0 ) {
804802 active_fork . remove ( ) ;
805803 }
@@ -845,14 +843,14 @@ export function schedule_effect(signal) {
845843 */
846844function process_effects ( root , async_effects , render_effects , effects ) {
847845 var effect = root . first ;
846+ var fork = /** @type {Fork } */ ( active_fork ) ;
848847
849848 while ( effect !== null ) {
850849 var flags = effect . f ;
851850 var is_branch = ( flags & BRANCH_EFFECT ) !== 0 ;
852851 var is_skippable_branch = is_branch && ( flags & CLEAN ) !== 0 ;
853852
854- var skip =
855- is_skippable_branch || ( flags & INERT ) !== 0 || active_fork ?. skipped_effects . has ( effect ) ;
853+ var skip = is_skippable_branch || ( flags & INERT ) !== 0 || fork . skipped_effects . has ( effect ) ;
856854
857855 if ( ! skip ) {
858856 if ( ( flags & EFFECT_ASYNC ) !== 0 ) {
0 commit comments