handle errors in async block expressions

pull/15844/head
Rich Harris 3 months ago
parent 2c2557aaa8
commit 2fd762863a

@ -1,7 +1,7 @@
/** @import { Effect, TemplateNode, Value } from '#client' */ /** @import { Effect, TemplateNode, Value } from '#client' */
import { DESTROYED } from '#client/constants'; import { DESTROYED } from '#client/constants';
import { async_derived } from '../../reactivity/deriveds.js'; import { async_derived } from '../../reactivity/deriveds.js';
import { active_effect } from '../../runtime.js'; import { active_effect, get } from '../../runtime.js';
import { capture, get_pending_boundary } from './boundary.js'; import { capture, get_pending_boundary } from './boundary.js';
/** /**
@ -20,12 +20,15 @@ export async function async(node, expressions, fn) {
boundary.update_pending_count(1); boundary.update_pending_count(1);
try { try {
const result = await Promise.all(expressions.map((fn) => async_derived(fn))); const deriveds = await Promise.all(expressions.map((fn) => async_derived(fn)));
// get deriveds eagerly to avoid creating blocks if they reject
for (const d of deriveds) get(d);
if ((parent.f & DESTROYED) !== 0) return; if ((parent.f & DESTROYED) !== 0) return;
restore(); restore();
fn(node, ...result); fn(node, ...deriveds);
} catch (error) { } catch (error) {
boundary.error(error); boundary.error(error);
} finally { } finally {

@ -0,0 +1,11 @@
import { tick } from 'svelte';
import { test } from '../../test';
export default test({
html: `loading`,
async test({ assert, target }) {
await tick();
assert.htmlEqual(target.innerHTML, 'oops');
}
});

@ -0,0 +1,8 @@
<svelte:boundary>
{#each (await Promise.reject(new Error('oops'))) as x}
hi
{/each}
{#snippet pending()}loading{/snippet}
{#snippet failed()}oops{/snippet}
</svelte:boundary>
Loading…
Cancel
Save