Skip to content

Commit b5c8437

Browse files
authored
fix: flush batches whenever an async value resolves (#16912)
* fix: flush batches whenever an async value resolves * move some code around * unnecessary
1 parent 06bd6a8 commit b5c8437

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

.changeset/metal-parents-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: flush batches whenever an async value resolves

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ export function flatten(sync, async, fn) {
5252

5353
Promise.all(async.map((expression) => async_derived(expression)))
5454
.then((result) => {
55-
batch?.activate();
56-
5755
restore();
5856

5957
try {

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

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ export class Batch {
178178
flush_queued_effects(render_effects);
179179
flush_queued_effects(effects);
180180

181+
previous_batch = null;
182+
181183
this.#deferred?.resolve();
182184
} else {
183185
this.#defer_effects(this.#render_effects);
@@ -280,17 +282,6 @@ export class Batch {
280282

281283
deactivate() {
282284
current_batch = null;
283-
previous_batch = null;
284-
285-
for (const update of effect_pending_updates) {
286-
effect_pending_updates.delete(update);
287-
update();
288-
289-
if (current_batch !== null) {
290-
// only do one at a time
291-
break;
292-
}
293-
}
294285
}
295286

296287
flush() {
@@ -307,6 +298,16 @@ export class Batch {
307298
}
308299

309300
this.deactivate();
301+
302+
for (const update of effect_pending_updates) {
303+
effect_pending_updates.delete(update);
304+
update();
305+
306+
if (current_batch !== null) {
307+
// only do one at a time
308+
break;
309+
}
310+
}
310311
}
311312

312313
/**
@@ -375,21 +376,17 @@ export class Batch {
375376
decrement() {
376377
this.#pending -= 1;
377378

378-
if (this.#pending === 0) {
379-
for (const e of this.#dirty_effects) {
380-
set_signal_status(e, DIRTY);
381-
schedule_effect(e);
382-
}
383-
384-
for (const e of this.#maybe_dirty_effects) {
385-
set_signal_status(e, MAYBE_DIRTY);
386-
schedule_effect(e);
387-
}
379+
for (const e of this.#dirty_effects) {
380+
set_signal_status(e, DIRTY);
381+
schedule_effect(e);
382+
}
388383

389-
this.flush();
390-
} else {
391-
this.deactivate();
384+
for (const e of this.#maybe_dirty_effects) {
385+
set_signal_status(e, MAYBE_DIRTY);
386+
schedule_effect(e);
392387
}
388+
389+
this.flush();
393390
}
394391

395392
/** @param {() => void} fn */

0 commit comments

Comments
 (0)