fix: skip destroyed eager effects and execute in order of depth

pull/16930/head
David Roizenman 10 months ago
parent 36ccef80bf
commit 7b029d51e2
No known key found for this signature in database
GPG Key ID: CD7B405D13E241B6

@ -601,15 +601,32 @@ function flush_queued_effects(effects) {
// If update_effect() has a flushSync() in it, we may have flushed another flush_queued_effects(),
// which already handled this logic and did set eager_block_effects to null.
if (eager_block_effects?.length > 0) {
// TODO this feels incorrect! it gets the tests passing
old_values.clear();
/** @type {Array<{ effect: Effect; depth: number }>} */
const effects_with_depth = [];
for (const e of eager_block_effects) {
update_effect(e);
// Skip eager effects that have already been unmounted
if ((e.f & (DESTROYED | INERT)) !== 0) continue;
let depth = 0;
let ancestor = e.parent;
while (ancestor !== null) {
depth++;
ancestor = ancestor.parent;
}
effects_with_depth.push({ effect: e, depth });
}
eager_block_effects = [];
effects_with_depth.sort((a, b) => a.depth - b.depth);
for (const { effect } of effects_with_depth) {
update_effect(effect);
}
}
eager_block_effects = [];
}
}

Loading…
Cancel
Save