From 6979d476e5d51b6be13ad9d6483569f66ef7c3cb Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Thu, 16 Jan 2025 11:49:02 +0000 Subject: [PATCH] wip --- .../src/internal/client/dom/blocks/boundary.js | 15 +++++++++------ packages/svelte/src/internal/client/runtime.js | 5 ++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/svelte/src/internal/client/dom/blocks/boundary.js b/packages/svelte/src/internal/client/dom/blocks/boundary.js index 87070fa65e..c5043559c8 100644 --- a/packages/svelte/src/internal/client/dom/blocks/boundary.js +++ b/packages/svelte/src/internal/client/dom/blocks/boundary.js @@ -1,7 +1,7 @@ /** @import { Effect, Source, TemplateNode, } from '#client' */ import { UNINITIALIZED } from '../../../../constants.js'; -import { AWAIT_EFFECT, BOUNDARY_EFFECT, EFFECT_TRANSPARENT, PENDING } from '../../constants.js'; +import { AWAIT_EFFECT, BOUNDARY_EFFECT, EFFECT_TRANSPARENT, INERT, PENDING } from '../../constants.js'; import { derived } from '../../reactivity/deriveds.js'; import { block, @@ -254,8 +254,11 @@ export function trigger_async_boundary(effect, trigger) { */ export function await_derived(fn) { var current = active_effect; - /** @type {Source} */ - var value = source(PENDING); + /** @type {Source} */ + var value = source(UNINITIALIZED); + // We mark the source signal as inert as it's value + // can throw if in an async pending state + value.f ^= INERT; /** @type {Promise | typeof UNINITIALIZED} */ var previous_promise = UNINITIALIZED; var derived_promise = derived(fn); @@ -276,9 +279,6 @@ export function await_derived(fn) { if (should_suspend) { set_is_within_await(true); - untrack(() => { - set(value, PENDING); - }); trigger_async_boundary(current, ASYNC_INCREMENT); // If we're updating, then we need to flush the boundary microtasks @@ -287,6 +287,9 @@ export function await_derived(fn) { } promise.then((v) => { + if (previous_promise !== promise) { + return; + } set(value, v); trigger_async_boundary(current, ASYNC_DECREMENT); }); diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 03bbe34625..4f7457376e 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -1035,7 +1035,10 @@ export function get(signal) { value = signal.v; - if (value === PENDING) { + if ( + (flags & INERT) !== 0 && + (is_within_await || (active_effect !== null && (active_effect.f & INERT) !== 0)) + ) { throw PENDING; }