From 494f06aad156bf663c75a205f1e780aa2a8bc1b3 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 30 Mar 2026 14:20:51 -0400 Subject: [PATCH] WIP --- .../src/internal/client/reactivity/async.js | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/async.js b/packages/svelte/src/internal/client/reactivity/async.js index 3a0569bcdd..b5a5989fac 100644 --- a/packages/svelte/src/internal/client/reactivity/async.js +++ b/packages/svelte/src/internal/client/reactivity/async.js @@ -38,8 +38,22 @@ export function flatten(blockers, sync, async, fn) { // Filter out already-settled blockers - no need to wait for them var pending = blockers.filter((b) => !b.settled); + var deriveds = sync.map(d); + + if (DEV) { + deriveds.forEach((d, i) => { + // TODO this is kinda useful for debugging but a lousy implementation — + // maybe the compiler could pass through the template string + d.label = sync[i] + .toString() + .replace('() => ', '') + .replaceAll('$.eager(() => ', '$state.eager(') + .replace(/\$\.get\((.+?)\)/g, (_, id) => id); + }); + } + if (async.length === 0 && pending.length === 0) { - fn(sync.map(d)); + fn(deriveds); return; } @@ -54,14 +68,13 @@ export function flatten(blockers, sync, async, fn) { : null; /** - * @param {Array<() => any>} sync * @param {Source[]} async */ - function finish(sync, async) { + function finish(async) { restore(); try { - fn([...sync.map(d), ...async]); + fn([...deriveds, ...async]); } catch (error) { if ((parent.f & DESTROYED) === 0) { invoke_error_boundary(error, parent); @@ -73,7 +86,7 @@ export function flatten(blockers, sync, async, fn) { // Fast path: blockers but no async expressions if (async.length === 0) { - /** @type {Promise} */ (blocker_promise).then(() => finish(sync, [])); + /** @type {Promise} */ (blocker_promise).then(() => finish([])); return; } @@ -82,7 +95,7 @@ export function flatten(blockers, sync, async, fn) { // Full path: has async expressions function run() { Promise.all(async.map((expression) => async_derived(expression))) - .then((result) => finish(sync, result)) + .then(finish) .catch((error) => invoke_error_boundary(error, parent)) .finally(() => decrement_pending()); }