@@ -193,15 +193,15 @@ export class Batch {
193193 // if we didn't start any new async work, and no async work
194194 // is outstanding from a previous flush, commit
195195 if ( this . #async_effects. length === 0 && this . #pending === 0 ) {
196+ this . #commit( ) ;
197+
196198 var render_effects = this . #render_effects;
197199 var effects = this . #effects;
198200
199201 this . #render_effects = [ ] ;
200202 this . #effects = [ ] ;
201203 this . #block_effects = [ ] ;
202204
203- this . #commit( ) ;
204-
205205 flush_queued_effects ( render_effects ) ;
206206 flush_queued_effects ( effects ) ;
207207
@@ -539,43 +539,43 @@ function flush_queued_effects(effects) {
539539 var length = effects . length ;
540540 if ( length === 0 ) return ;
541541
542- for ( var i = 0 ; i < length ; i ++ ) {
543- var effect = effects [ i ] ;
544-
545- if ( ( effect . f & ( DESTROYED | INERT ) ) === 0 ) {
546- if ( is_dirty ( effect ) ) {
547- var wv = write_version ;
548-
549- update_effect ( effect ) ;
550-
551- // Effects with no dependencies or teardown do not get added to the effect tree.
552- // Deferred effects (e.g. `$effect(...)`) _are_ added to the tree because we
553- // don't know if we need to keep them until they are executed. Doing the check
554- // here (rather than in `update_effect`) allows us to skip the work for
555- // immediate effects.
556- if ( effect . deps === null && effect . first === null && effect . nodes_start === null ) {
557- // if there's no teardown or abort controller we completely unlink
558- // the effect from the graph
559- if ( effect . teardown === null && effect . ac === null ) {
560- // remove this effect from the graph
561- unlink_effect ( effect ) ;
562- } else {
563- // keep the effect in the graph, but free up some memory
564- effect . fn = null ;
565- }
566- }
542+ var i = 0 ;
567543
568- // if state is written in a user effect, abort and re-schedule, lest we run
569- // effects that should be removed as a result of the state change
570- if ( write_version > wv && ( effect . f & USER_EFFECT ) !== 0 ) {
571- break ;
544+ while ( i < length ) {
545+ var effect = effects [ i ++ ] ;
546+
547+ if ( ( effect . f & ( DESTROYED | INERT ) ) === 0 && is_dirty ( effect ) ) {
548+ var wv = write_version ;
549+
550+ update_effect ( effect ) ;
551+
552+ // Effects with no dependencies or teardown do not get added to the effect tree.
553+ // Deferred effects (e.g. `$effect(...)`) _are_ added to the tree because we
554+ // don't know if we need to keep them until they are executed. Doing the check
555+ // here (rather than in `update_effect`) allows us to skip the work for
556+ // immediate effects.
557+ if ( effect . deps === null && effect . first === null && effect . nodes_start === null ) {
558+ // if there's no teardown or abort controller we completely unlink
559+ // the effect from the graph
560+ if ( effect . teardown === null && effect . ac === null ) {
561+ // remove this effect from the graph
562+ unlink_effect ( effect ) ;
563+ } else {
564+ // keep the effect in the graph, but free up some memory
565+ effect . fn = null ;
572566 }
573567 }
568+
569+ // if state is written in a user effect, abort and re-schedule, lest we run
570+ // effects that should be removed as a result of the state change
571+ if ( write_version > wv && ( effect . f & USER_EFFECT ) !== 0 ) {
572+ break ;
573+ }
574574 }
575575 }
576576
577- for ( ; i < length ; i += 1 ) {
578- schedule_effect ( effects [ i ] ) ;
577+ while ( i < length ) {
578+ schedule_effect ( effects [ i ++ ] ) ;
579579 }
580580}
581581
0 commit comments