Skip to content

Commit 48a781e

Browse files
committed
fix
1 parent 3d0b6f7 commit 48a781e

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

packages/svelte/src/internal/client/dom/blocks/async.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,24 @@ export function async(node, expressions, fn) {
1515

1616
var batch = /** @type {Batch} */ (current_batch);
1717
var effect = /** @type {Effect} */ (active_effect);
18+
1819
var boundary = get_pending_boundary(effect);
20+
var ran = boundary.ran;
1921

2022
var restore = capture();
2123

2224
boundary.increment();
2325

2426
Promise.all(expressions.map((fn) => async_derived(fn))).then((result) => {
25-
batch?.restore();
27+
if (ran) batch.restore();
2628

2729
restore();
2830
fn(node, ...result);
2931

3032
// TODO is this necessary?
3133
schedule_effect(effect);
3234

33-
batch?.flush();
35+
if (ran) batch.flush();
3436
boundary.decrement();
3537
});
3638
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export class Batch {
7474
}
7575

7676
for (const [source, current] of this.#current) {
77+
current_values.set(source, source.v);
78+
7779
// TODO this shouldn't be necessary, but tests fail otherwise,
7880
// presumably because we need a try-finally somewhere, and the
7981
// source wasn't correctly reverted after the previous batch
@@ -214,16 +216,16 @@ export class Batch {
214216
raf.tick(update_pending);
215217
}
216218

217-
current_batch = new Batch();
219+
const batch = (current_batch = new Batch());
218220
batches.add(current_batch);
219221

220222
queueMicrotask(() => {
221-
if (current_batch === null) {
223+
if (current_batch !== batch) {
222224
// a flushSync happened in the meantime
223225
return;
224226
}
225227

226-
current_batch.flush();
228+
batch.flush();
227229
});
228230
}
229231

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ export function async_derived(fn, location) {
162162
}
163163
}
164164

165-
batch?.restore();
165+
if (ran) batch.restore();
166166
internal_set(signal, v);
167-
batch?.flush();
167+
if (ran) batch.flush();
168168

169169
if (DEV && location !== undefined) {
170170
recent_async_deriveds.add(signal);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { DEV } from 'esm-env';
4040
import { define_property } from '../../shared/utils.js';
4141
import { get_next_sibling } from '../dom/operations.js';
4242
import { async_derived, derived } from './deriveds.js';
43-
import { capture } from '../dom/blocks/boundary.js';
43+
import { capture, get_pending_boundary } from '../dom/blocks/boundary.js';
4444
import { component_context, dev_current_component_function } from '../context.js';
4545
import { current_batch, Batch } from './batch.js';
4646

@@ -348,6 +348,9 @@ export function template_effect(fn, sync = [], async = [], d = derived) {
348348
var batch = /** @type {Batch} */ (current_batch);
349349
var restore = capture();
350350

351+
var boundary = get_pending_boundary(parent);
352+
var ran = boundary.ran;
353+
351354
Promise.all(async.map((expression) => async_derived(expression))).then((result) => {
352355
restore();
353356

@@ -357,9 +360,9 @@ export function template_effect(fn, sync = [], async = [], d = derived) {
357360

358361
var effect = create_template_effect(fn, [...sync.map(d), ...result]);
359362

360-
batch?.restore();
363+
if (ran) batch.restore();
361364
schedule_effect(effect);
362-
batch?.flush();
365+
if (ran) batch.flush();
363366
});
364367
} else {
365368
create_template_effect(fn, sync.map(d));

0 commit comments

Comments
 (0)