pull/16631/head
Rich Harris 3 weeks ago
parent d5ba21f77c
commit c9b2654357

@ -584,6 +584,9 @@ function infinite_loop_guard() {
}
}
/** @type {Effect[] | null} */
export let eager_block_effects = null;
/**
* @param {Array<Effect>} effects
* @returns {void}
@ -600,6 +603,8 @@ function flush_queued_effects(effects) {
if ((effect.f & (DESTROYED | INERT)) === 0 && is_dirty(effect)) {
var sv = schedule_version;
eager_block_effects = [];
update_effect(effect);
// Effects with no dependencies or teardown do not get added to the effect tree.
@ -619,14 +624,24 @@ function flush_queued_effects(effects) {
}
}
if (eager_block_effects.length > 0) {
for (const e of eager_block_effects) {
update_effect(e);
}
eager_block_effects = [];
}
// if a state change in a user effect invalidates a _different_ effect,
// abort and reschedule in case that effect now needs to be destroyed
if (schedule_version > sv && (effect.f & USER_EFFECT) !== 0) {
break;
// break;
}
}
}
eager_block_effects = null;
while (i < length) {
schedule_effect(effects[i++]);
}

@ -33,7 +33,7 @@ import * as e from '../errors.js';
import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js';
import { get_stack, tag_proxy } from '../dev/tracing.js';
import { component_context, is_runes } from '../context.js';
import { Batch, schedule_effect } from './batch.js';
import { Batch, eager_block_effects, schedule_effect } from './batch.js';
import { proxy } from '../proxy.js';
import { execute_derived } from './deriveds.js';
@ -340,7 +340,13 @@ function mark_reactions(signal, status) {
if ((flags & DERIVED) !== 0) {
mark_reactions(/** @type {Derived} */ (reaction), MAYBE_DIRTY);
} else if (not_dirty) {
if ((flags & BLOCK_EFFECT) !== 0) schedule_version += 1;
if ((flags & BLOCK_EFFECT) !== 0) {
if (eager_block_effects !== null) {
eager_block_effects.push(/** @type {Effect} */ (reaction));
}
schedule_version += 1;
}
schedule_effect(/** @type {Effect} */ (reaction));
}
}

Loading…
Cancel
Save