fix: flush batches whenever an async value resolves (#16912)

* fix: flush batches whenever an async value resolves

* move some code around

* unnecessary
pull/16913/head
Rich Harris 1 month ago committed by GitHub
parent 06bd6a8fbd
commit b5c8437151
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: flush batches whenever an async value resolves

@ -52,8 +52,6 @@ export function flatten(sync, async, fn) {
Promise.all(async.map((expression) => async_derived(expression))) Promise.all(async.map((expression) => async_derived(expression)))
.then((result) => { .then((result) => {
batch?.activate();
restore(); restore();
try { try {

@ -178,6 +178,8 @@ export class Batch {
flush_queued_effects(render_effects); flush_queued_effects(render_effects);
flush_queued_effects(effects); flush_queued_effects(effects);
previous_batch = null;
this.#deferred?.resolve(); this.#deferred?.resolve();
} else { } else {
this.#defer_effects(this.#render_effects); this.#defer_effects(this.#render_effects);
@ -280,17 +282,6 @@ export class Batch {
deactivate() { deactivate() {
current_batch = null; current_batch = null;
previous_batch = null;
for (const update of effect_pending_updates) {
effect_pending_updates.delete(update);
update();
if (current_batch !== null) {
// only do one at a time
break;
}
}
} }
flush() { flush() {
@ -307,6 +298,16 @@ export class Batch {
} }
this.deactivate(); this.deactivate();
for (const update of effect_pending_updates) {
effect_pending_updates.delete(update);
update();
if (current_batch !== null) {
// only do one at a time
break;
}
}
} }
/** /**
@ -375,7 +376,6 @@ export class Batch {
decrement() { decrement() {
this.#pending -= 1; this.#pending -= 1;
if (this.#pending === 0) {
for (const e of this.#dirty_effects) { for (const e of this.#dirty_effects) {
set_signal_status(e, DIRTY); set_signal_status(e, DIRTY);
schedule_effect(e); schedule_effect(e);
@ -387,9 +387,6 @@ export class Batch {
} }
this.flush(); this.flush();
} else {
this.deactivate();
}
} }
/** @param {() => void} fn */ /** @param {() => void} fn */

Loading…
Cancel
Save