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() { flush() {
if (queued_root_effects.length > 0) { if (queued_root_effects.length > 0) {
flush_effects(); flush_effects();
} else { } else if (this.#pending === 0) {
this.#commit(); this.#commit();
} }
@ -417,6 +417,7 @@ export class Batch {
this.#pending -= 1; this.#pending -= 1;
if (this.#pending === 0) { if (this.#pending === 0) {
Batch.enqueue(() => {
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);
@ -431,6 +432,7 @@ export class Batch {
this.#effects = []; this.#effects = [];
this.flush(); this.flush();
});
} else { } else {
this.deactivate(); this.deactivate();
} }
@ -670,20 +672,14 @@ export function schedule_effect(signal) {
export function suspend() { export function suspend() {
var boundary = get_pending_boundary(); var boundary = get_pending_boundary();
var batch = /** @type {Batch} */ (current_batch); var batch = /** @type {Batch} */ (current_batch);
var pending = boundary.pending;
boundary.update_pending_count(1); boundary.update_pending_count(1);
if (!pending) batch.increment(); batch.increment();
return function unsuspend() { return function unsuspend() {
boundary.update_pending_count(-1); boundary.update_pending_count(-1);
if (!pending) {
batch.activate(); batch.activate();
batch.decrement(); batch.decrement();
} else {
batch.deactivate();
}
unset_context(); unset_context();
}; };
@ -694,4 +690,5 @@ export function suspend() {
*/ */
export function clear() { export function clear() {
batches.clear(); batches.clear();
tasks.length = 0;
} }

@ -135,11 +135,10 @@ export function async_derived(fn, location) {
prev = promise; prev = promise;
var batch = /** @type {Batch} */ (current_batch); var batch = /** @type {Batch} */ (current_batch);
var pending = boundary.pending;
if (should_suspend) { if (should_suspend) {
boundary.update_pending_count(1); 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; current_async_effect = null;
if (!pending) batch.activate(); batch.activate();
if (error) { if (error) {
if (error !== STALE_REACTION) { if (error !== STALE_REACTION) {
@ -181,7 +180,7 @@ export function async_derived(fn, location) {
if (should_suspend) { if (should_suspend) {
boundary.update_pending_count(-1); boundary.update_pending_count(-1);
if (!pending) batch.decrement(); batch.decrement();
} }
unset_context(); unset_context();

Loading…
Cancel
Save