@@ -184,9 +184,12 @@ export class Batch {
184184 /** @type {Map<Source, { v: unknown, wv: number }> | null } */
185185 var current_values = null ;
186186
187- // if there are multiple batches, we are 'time travelling' —
187+ // If there are multiple batches, we are 'time travelling' —
188188 // we need to undo the changes belonging to any batch
189- // other than the current one
189+ // other than the current one.
190+ // In case of block_effects_only we've already created a new batch
191+ // due to an effect writing to a source, and we're eagerly flushing
192+ // that batch while the old one is still active, hence > 2 in that case.
190193 if ( batches . size > ( block_effects_only ? 2 : 1 ) ) {
191194 current_values = new Map ( ) ;
192195 batch_deriveds = new Map ( ) ;
@@ -214,6 +217,7 @@ export class Batch {
214217
215218 if ( block_effects_only ) {
216219 queued_root_effects = root_effects ;
220+ this . #commit( ) ;
217221 return ;
218222 }
219223
@@ -304,12 +308,15 @@ export class Batch {
304308 }
305309 } else if ( is_branch ) {
306310 effect . f ^= CLEAN ;
311+ } else if ( ( flags & EFFECT ) !== 0 ) {
312+ // Push into effects regardly of dirty status, so that one effect making
313+ // a subsequent effect dirty will not cause it to be postponed until the next flush
314+ this . #effects. push ( effect ) ;
315+ } else if ( async_mode_flag && ( flags & RENDER_EFFECT ) !== 0 ) {
316+ // Same as for #effects
317+ this . #render_effects. push ( effect ) ;
307318 } else if ( ( flags & CLEAN ) === 0 ) {
308- if ( ( flags & EFFECT ) !== 0 ) {
309- this . #effects. push ( effect ) ;
310- } else if ( async_mode_flag && ( flags & RENDER_EFFECT ) !== 0 ) {
311- this . #render_effects. push ( effect ) ;
312- } else if ( ( flags & ASYNC ) !== 0 ) {
319+ if ( ( flags & ASYNC ) !== 0 ) {
313320 var effects = effect . b ?. pending ? this . #boundary_async_effects : this . #async_effects;
314321 effects . push ( effect ) ;
315322 } else if ( is_dirty ( effect ) ) {
@@ -410,6 +417,7 @@ export class Batch {
410417
411418 flush_block_effects ( ) {
412419 if ( queued_root_effects . length > 0 ) {
420+ old_values . clear ( ) ;
413421 this . process ( queued_root_effects , true ) ;
414422 }
415423 }
0 commit comments