Skip to content

Commit 18ecf01

Browse files
committed
WIP
1 parent ae0038c commit 18ecf01

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,10 @@ export async function async_body(fn) {
203203
var boundary = get_boundary();
204204
var batch = /** @type {Batch} */ (current_batch);
205205

206+
var blocking = !boundary.is_pending();
207+
206208
boundary.update_pending_count(1);
207-
batch.increment();
209+
batch.increment(blocking);
208210

209211
var active = /** @type {Effect} */ (active_effect);
210212

@@ -237,7 +239,7 @@ export async function async_body(fn) {
237239
}
238240

239241
boundary.update_pending_count(-1);
240-
batch.decrement();
242+
batch.decrement(blocking);
241243

242244
unset_context();
243245
}

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ export class Batch {
101101
*/
102102
#pending = 0;
103103

104+
/**
105+
* The number of async effects that are currently in flight, _not_ inside a pending boundary
106+
*/
107+
#blocking_pending = 0;
108+
104109
/**
105110
* A deferred that resolves when the batch is committed, used with `settled()`
106111
* TODO replace with Promise.withResolvers once supported widely enough
@@ -257,7 +262,7 @@ export class Batch {
257262
}
258263
}
259264

260-
if (should_defer) {
265+
if (this.#blocking_pending > 0) {
261266
this.#defer_effects(target.effects);
262267
this.#defer_effects(target.render_effects);
263268
this.#defer_effects(target.block_effects);
@@ -407,12 +412,22 @@ export class Batch {
407412
this.#deferred?.resolve();
408413
}
409414

410-
increment() {
415+
/**
416+
*
417+
* @param {boolean} blocking
418+
*/
419+
increment(blocking) {
411420
this.#pending += 1;
421+
if (blocking) this.#blocking_pending += 1;
412422
}
413423

414-
decrement() {
424+
/**
425+
*
426+
* @param {boolean} blocking
427+
*/
428+
decrement(blocking) {
415429
this.#pending -= 1;
430+
if (blocking) this.#blocking_pending -= 1;
416431

417432
for (const e of this.#dirty_effects) {
418433
set_signal_status(e, DIRTY);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ export function async_derived(fn, location) {
138138
var batch = /** @type {Batch} */ (current_batch);
139139

140140
if (should_suspend) {
141+
var blocking = !boundary.is_pending();
142+
141143
boundary.update_pending_count(1);
142-
batch.increment();
144+
batch.increment(blocking);
143145

144146
deferreds.get(batch)?.reject(STALE_REACTION);
145147
deferreds.delete(batch); // delete to ensure correct order in Map iteration below
@@ -190,7 +192,7 @@ export function async_derived(fn, location) {
190192

191193
if (should_suspend) {
192194
boundary.update_pending_count(-1);
193-
batch.decrement();
195+
batch.decrement(blocking);
194196
}
195197
};
196198

0 commit comments

Comments
 (0)