fix: correct first processing of boundary with pending snippet

WIP
boundary-batch-first-run
Simon Holthausen 2 weeks ago
parent 2344b4052e
commit 1211fdc5f6

@ -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;
}

@ -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();

Loading…
Cancel
Save