From ecdfd5b40ccd41894263e03ab806772c9faabe3f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 26 Sep 2025 15:42:38 -0400 Subject: [PATCH] fix --- .../src/internal/client/reactivity/batch.js | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/batch.js b/packages/svelte/src/internal/client/reactivity/batch.js index 726b824109..058084b14b 100644 --- a/packages/svelte/src/internal/client/reactivity/batch.js +++ b/packages/svelte/src/internal/client/reactivity/batch.js @@ -350,8 +350,6 @@ export class Batch { this.#callbacks.clear(); if (batches.size > 1) { - const effects = new Set(); - /** * @param {Value} value * @param {Set} effects @@ -370,24 +368,32 @@ export class Batch { } }; - for (const source of this.current.keys()) { - // TODO do we also need block effects? - get_async_effects(source, effects); - } - this.#previous.clear(); + let is_earlier = true; + for (const batch of batches) { if (batch === this) { + is_earlier = true; continue; } - current_batch = batch; - const revert = Batch.apply(batch); - for (const e of effects) { - update_effect(e); + const effects = new Set(); + + for (const source of this.current.keys()) { + if (is_earlier && batch.current.has(source)) continue; + // TODO do we also need block effects? + get_async_effects(source, effects); + } + + if (effects.size > 0) { + current_batch = batch; + const revert = Batch.apply(batch); + for (const e of effects) { + update_effect(e); + } + revert(); } - revert(); } current_batch = null;