From 3fe77cdebe4b1e77dbf07c55c758d9c84e1a3dd9 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 19 Apr 2025 12:58:12 -0400 Subject: [PATCH] tweak --- .../internal/client/reactivity/deriveds.js | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/deriveds.js b/packages/svelte/src/internal/client/reactivity/deriveds.js index 5dfa554732..17f41d856f 100644 --- a/packages/svelte/src/internal/client/reactivity/deriveds.js +++ b/packages/svelte/src/internal/client/reactivity/deriveds.js @@ -100,18 +100,22 @@ export function async_derived(fn, location) { throw new Error('TODO cannot create unowned async derived'); } + let boundary = parent.b; + + while (boundary !== null && !boundary.has_pending_snippet()) { + boundary = boundary.parent; + } + + if (boundary === null) { + throw new Error('TODO cannot create async derived outside a boundary with a pending snippet'); + } + var promise = /** @type {Promise} */ (/** @type {unknown} */ (undefined)); var signal = source(/** @type {V} */ (UNINITIALIZED)); // only suspend in async deriveds created on initialisation var should_suspend = !active_reaction; - var boundary = /** @type {Effect} */ parent.b; - - while (boundary !== null && !boundary.has_pending_snippet()) { - boundary = boundary.parent; - } - render_effect(() => { if (DEV) from_async_derived = active_effect; promise = fn(); @@ -125,10 +129,6 @@ export function async_derived(fn, location) { if (fork !== null) { fork.increment(); } else { - if (boundary === null) { - throw new Error('TODO'); - } - // if nearest pending boundary is not ready, attach to the boundary boundary.increment(); } @@ -147,10 +147,6 @@ export function async_derived(fn, location) { if (fork !== null) { fork.decrement(); } else { - if (boundary === null) { - throw new Error('TODO'); - } - boundary.decrement(); } }