pull/15844/head
Rich Harris 2 months ago
parent 12188f37f6
commit 4d8432a0f2

@ -14,10 +14,13 @@ export function async(node, expressions, fn) {
boundary.update_pending_count(1); boundary.update_pending_count(1);
flatten([], expressions, (values) => { flatten([], expressions, (values) => {
try {
// get values eagerly to avoid creating blocks if they reject // get values eagerly to avoid creating blocks if they reject
for (const d of values) get(d); for (const d of values) get(d);
fn(node, ...values); fn(node, ...values);
} finally {
boundary.update_pending_count(-1); boundary.update_pending_count(-1);
}
}); });
} }

@ -27,8 +27,6 @@ export function flatten(sync, async, fn) {
Promise.all(async.map((expression) => async_derived(expression))) Promise.all(async.map((expression) => async_derived(expression)))
.then((result) => { .then((result) => {
if ((parent.f & DESTROYED) !== 0) return;
batch?.activate(); batch?.activate();
restore(); restore();
@ -36,8 +34,11 @@ export function flatten(sync, async, fn) {
try { try {
fn([...sync.map(d), ...result]); fn([...sync.map(d), ...result]);
} catch (error) { } catch (error) {
// ignore errors in blocks that have already been destroyed
if ((parent.f & DESTROYED) === 0) {
invoke_error_boundary(error, parent); invoke_error_boundary(error, parent);
} }
}
batch?.deactivate(); batch?.deactivate();
}) })

@ -2,23 +2,24 @@ import { tick } from 'svelte';
import { test } from '../../test'; import { test } from '../../test';
export default test({ export default test({
async test({ assert, target }) { async test({ assert, target, errors }) {
const [increment, shift] = target.querySelectorAll('button'); const [increment, resolve, reject] = target.querySelectorAll('button');
increment.click(); increment.click();
await tick(); await tick();
shift.click(); reject.click();
await tick(); await tick();
shift.click(); resolve.click();
await tick(); await tick();
assert.htmlEqual( assert.htmlEqual(
target.innerHTML, target.innerHTML,
` `
<button>increment</button> <button>increment</button>
<button>shift</button> <button>resolve</button>
<button>reject</button>
<p>false</p> <p>false</p>
<p>1</p> <p>1</p>
` `

Loading…
Cancel
Save