Skip to content

Commit c3aabc1

Browse files
committed
tweak logic to make it clearer why and when we commit a batch
1 parent 6b1ac77 commit c3aabc1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/svelte/src/internal/client/reactivity/batch.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
flush_queued_effects,
66
flush_queued_root_effects,
77
process_effects,
8+
queued_root_effects,
89
schedule_effect,
910
set_queued_root_effects,
1011
set_signal_status,
@@ -174,7 +175,7 @@ export class Batch {
174175
this.render_effects = [];
175176
this.effects = [];
176177

177-
this.commit();
178+
this.#commit();
178179

179180
flush_queued_effects(render_effects);
180181
flush_queued_effects(effects);
@@ -227,7 +228,11 @@ export class Batch {
227228
}
228229

229230
flush() {
230-
flush_queued_root_effects();
231+
if (queued_root_effects.length > 0) {
232+
flush_queued_root_effects();
233+
} else {
234+
this.#commit();
235+
}
231236

232237
if (current_batch !== this) {
233238
// this can happen if a `flushSync` occurred during `flush_queued_root_effects`,
@@ -242,7 +247,7 @@ export class Batch {
242247
current_batch = null;
243248
}
244249

245-
commit() {
250+
#commit() {
246251
for (const fn of this.#callbacks) {
247252
fn();
248253
}
@@ -270,8 +275,6 @@ export class Batch {
270275

271276
this.render_effects = [];
272277
this.effects = [];
273-
274-
this.commit();
275278
}
276279
}
277280

packages/svelte/src/internal/client/runtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function set_is_destroying_effect(value) {
6868
// Handle effect queues
6969

7070
/** @type {Effect[]} */
71-
let queued_root_effects = [];
71+
export let queued_root_effects = [];
7272

7373
/** @param {Effect[]} v */
7474
export function set_queued_root_effects(v) {

0 commit comments

Comments
 (0)