pull/16197/head
Rich Harris 5 months ago
parent 3d0b6f71c4
commit 48a781e2b1

@ -15,14 +15,16 @@ export function async(node, expressions, fn) {
var batch = /** @type {Batch} */ (current_batch);
var effect = /** @type {Effect} */ (active_effect);
var boundary = get_pending_boundary(effect);
var ran = boundary.ran;
var restore = capture();
boundary.increment();
Promise.all(expressions.map((fn) => async_derived(fn))).then((result) => {
batch?.restore();
if (ran) batch.restore();
restore();
fn(node, ...result);
@ -30,7 +32,7 @@ export function async(node, expressions, fn) {
// TODO is this necessary?
schedule_effect(effect);
batch?.flush();
if (ran) batch.flush();
boundary.decrement();
});
}

@ -74,6 +74,8 @@ export class Batch {
}
for (const [source, current] of this.#current) {
current_values.set(source, source.v);
// TODO this shouldn't be necessary, but tests fail otherwise,
// presumably because we need a try-finally somewhere, and the
// source wasn't correctly reverted after the previous batch
@ -214,16 +216,16 @@ export class Batch {
raf.tick(update_pending);
}
current_batch = new Batch();
const batch = (current_batch = new Batch());
batches.add(current_batch);
queueMicrotask(() => {
if (current_batch === null) {
if (current_batch !== batch) {
// a flushSync happened in the meantime
return;
}
current_batch.flush();
batch.flush();
});
}

@ -162,9 +162,9 @@ export function async_derived(fn, location) {
}
}
batch?.restore();
if (ran) batch.restore();
internal_set(signal, v);
batch?.flush();
if (ran) batch.flush();
if (DEV && location !== undefined) {
recent_async_deriveds.add(signal);

@ -40,7 +40,7 @@ import { DEV } from 'esm-env';
import { define_property } from '../../shared/utils.js';
import { get_next_sibling } from '../dom/operations.js';
import { async_derived, derived } from './deriveds.js';
import { capture } from '../dom/blocks/boundary.js';
import { capture, get_pending_boundary } from '../dom/blocks/boundary.js';
import { component_context, dev_current_component_function } from '../context.js';
import { current_batch, Batch } from './batch.js';
@ -348,6 +348,9 @@ export function template_effect(fn, sync = [], async = [], d = derived) {
var batch = /** @type {Batch} */ (current_batch);
var restore = capture();
var boundary = get_pending_boundary(parent);
var ran = boundary.ran;
Promise.all(async.map((expression) => async_derived(expression))).then((result) => {
restore();
@ -357,9 +360,9 @@ export function template_effect(fn, sync = [], async = [], d = derived) {
var effect = create_template_effect(fn, [...sync.map(d), ...result]);
batch?.restore();
if (ran) batch.restore();
schedule_effect(effect);
batch?.flush();
if (ran) batch.flush();
});
} else {
create_template_effect(fn, sync.map(d));

Loading…
Cancel
Save