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)))
.then((result) => {
batch?.activate();
restore();
try {

@ -178,6 +178,8 @@ export class Batch {
flush_queued_effects(render_effects);
flush_queued_effects(effects);
previous_batch = null;
this.#deferred?.resolve();
} else {
this.#defer_effects(this.#render_effects);
@ -280,17 +282,6 @@ export class Batch {
deactivate() {
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() {
@ -307,6 +298,16 @@ export class Batch {
}
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,21 +376,17 @@ export class Batch {
decrement() {
this.#pending -= 1;
if (this.#pending === 0) {
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.#dirty_effects) {
set_signal_status(e, DIRTY);
schedule_effect(e);
}
this.flush();
} else {
this.deactivate();
for (const e of this.#maybe_dirty_effects) {
set_signal_status(e, MAYBE_DIRTY);
schedule_effect(e);
}
this.flush();
}
/** @param {() => void} fn */

Loading…
Cancel
Save