Skip to content

Commit 1211fdc

Browse files
committed
fix: correct first processing of boundary with pending snippet
WIP
1 parent 2344b40 commit 1211fdc

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

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

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export class Batch {
379379
flush() {
380380
if (queued_root_effects.length > 0) {
381381
flush_effects();
382-
} else {
382+
} else if (this.#pending === 0) {
383383
this.#commit();
384384
}
385385

@@ -417,20 +417,22 @@ export class Batch {
417417
this.#pending -= 1;
418418

419419
if (this.#pending === 0) {
420-
for (const e of this.#dirty_effects) {
421-
set_signal_status(e, DIRTY);
422-
schedule_effect(e);
423-
}
420+
Batch.enqueue(() => {
421+
for (const e of this.#dirty_effects) {
422+
set_signal_status(e, DIRTY);
423+
schedule_effect(e);
424+
}
424425

425-
for (const e of this.#maybe_dirty_effects) {
426-
set_signal_status(e, MAYBE_DIRTY);
427-
schedule_effect(e);
428-
}
426+
for (const e of this.#maybe_dirty_effects) {
427+
set_signal_status(e, MAYBE_DIRTY);
428+
schedule_effect(e);
429+
}
429430

430-
this.#render_effects = [];
431-
this.#effects = [];
431+
this.#render_effects = [];
432+
this.#effects = [];
432433

433-
this.flush();
434+
this.flush();
435+
});
434436
} else {
435437
this.deactivate();
436438
}
@@ -670,20 +672,14 @@ export function schedule_effect(signal) {
670672
export function suspend() {
671673
var boundary = get_pending_boundary();
672674
var batch = /** @type {Batch} */ (current_batch);
673-
var pending = boundary.pending;
674675

675676
boundary.update_pending_count(1);
676-
if (!pending) batch.increment();
677+
batch.increment();
677678

678679
return function unsuspend() {
679680
boundary.update_pending_count(-1);
680-
681-
if (!pending) {
682-
batch.activate();
683-
batch.decrement();
684-
} else {
685-
batch.deactivate();
686-
}
681+
batch.activate();
682+
batch.decrement();
687683

688684
unset_context();
689685
};
@@ -694,4 +690,5 @@ export function suspend() {
694690
*/
695691
export function clear() {
696692
batches.clear();
693+
tasks.length = 0;
697694
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,10 @@ export function async_derived(fn, location) {
135135
prev = promise;
136136

137137
var batch = /** @type {Batch} */ (current_batch);
138-
var pending = boundary.pending;
139138

140139
if (should_suspend) {
141140
boundary.update_pending_count(1);
142-
if (!pending) batch.increment();
141+
batch.increment();
143142
}
144143

145144
/**
@@ -151,7 +150,7 @@ export function async_derived(fn, location) {
151150

152151
current_async_effect = null;
153152

154-
if (!pending) batch.activate();
153+
batch.activate();
155154

156155
if (error) {
157156
if (error !== STALE_REACTION) {
@@ -181,7 +180,7 @@ export function async_derived(fn, location) {
181180

182181
if (should_suspend) {
183182
boundary.update_pending_count(-1);
184-
if (!pending) batch.decrement();
183+
batch.decrement();
185184
}
186185

187186
unset_context();

0 commit comments

Comments
 (0)