From 1211fdc5f6367ffd5f64b846b03ff35ce2f38608 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Wed, 3 Sep 2025 23:51:57 +0200 Subject: [PATCH] fix: correct first processing of boundary with pending snippet WIP --- .../src/internal/client/reactivity/batch.js | 39 +++++++++---------- .../internal/client/reactivity/deriveds.js | 7 ++-- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/batch.js b/packages/svelte/src/internal/client/reactivity/batch.js index 82f1de67a9..a6111f956a 100644 --- a/packages/svelte/src/internal/client/reactivity/batch.js +++ b/packages/svelte/src/internal/client/reactivity/batch.js @@ -379,7 +379,7 @@ export class Batch { flush() { if (queued_root_effects.length > 0) { flush_effects(); - } else { + } else if (this.#pending === 0) { this.#commit(); } @@ -417,20 +417,22 @@ export class Batch { this.#pending -= 1; if (this.#pending === 0) { - for (const e of this.#dirty_effects) { - set_signal_status(e, DIRTY); - schedule_effect(e); - } + Batch.enqueue(() => { + for (const e of this.#dirty_effects) { + set_signal_status(e, DIRTY); + schedule_effect(e); + } - for (const e of this.#maybe_dirty_effects) { - set_signal_status(e, MAYBE_DIRTY); - schedule_effect(e); - } + for (const e of this.#maybe_dirty_effects) { + set_signal_status(e, MAYBE_DIRTY); + schedule_effect(e); + } - this.#render_effects = []; - this.#effects = []; + this.#render_effects = []; + this.#effects = []; - this.flush(); + this.flush(); + }); } else { this.deactivate(); } @@ -670,20 +672,14 @@ export function schedule_effect(signal) { export function suspend() { var boundary = get_pending_boundary(); var batch = /** @type {Batch} */ (current_batch); - var pending = boundary.pending; boundary.update_pending_count(1); - if (!pending) batch.increment(); + batch.increment(); return function unsuspend() { boundary.update_pending_count(-1); - - if (!pending) { - batch.activate(); - batch.decrement(); - } else { - batch.deactivate(); - } + batch.activate(); + batch.decrement(); unset_context(); }; @@ -694,4 +690,5 @@ export function suspend() { */ export function clear() { batches.clear(); + tasks.length = 0; } diff --git a/packages/svelte/src/internal/client/reactivity/deriveds.js b/packages/svelte/src/internal/client/reactivity/deriveds.js index 31dc267960..b020b84723 100644 --- a/packages/svelte/src/internal/client/reactivity/deriveds.js +++ b/packages/svelte/src/internal/client/reactivity/deriveds.js @@ -135,11 +135,10 @@ export function async_derived(fn, location) { prev = promise; var batch = /** @type {Batch} */ (current_batch); - var pending = boundary.pending; if (should_suspend) { boundary.update_pending_count(1); - if (!pending) batch.increment(); + batch.increment(); } /** @@ -151,7 +150,7 @@ export function async_derived(fn, location) { current_async_effect = null; - if (!pending) batch.activate(); + batch.activate(); if (error) { if (error !== STALE_REACTION) { @@ -181,7 +180,7 @@ export function async_derived(fn, location) { if (should_suspend) { boundary.update_pending_count(-1); - if (!pending) batch.decrement(); + batch.decrement(); } unset_context();