diff --git a/packages/svelte/src/internal/client/dom/blocks/boundary.js b/packages/svelte/src/internal/client/dom/blocks/boundary.js index 8d85b24421..527d5e535f 100644 --- a/packages/svelte/src/internal/client/dom/blocks/boundary.js +++ b/packages/svelte/src/internal/client/dom/blocks/boundary.js @@ -140,7 +140,7 @@ export class Boundary { // the pending or main block was rendered for a given // boundary, and hydrate accordingly queueMicrotask(() => { - destroy_effect(/** @type {Effect} */ (this.#pending_effect)); + // destroy_effect(/** @type {Effect} */ (this.#pending_effect)); this.#main_effect = this.#run(() => { return branch(() => this.#children(this.#anchor)); diff --git a/packages/svelte/src/internal/client/reactivity/deriveds.js b/packages/svelte/src/internal/client/reactivity/deriveds.js index 12ea627461..6e3d6f6f9c 100644 --- a/packages/svelte/src/internal/client/reactivity/deriveds.js +++ b/packages/svelte/src/internal/client/reactivity/deriveds.js @@ -105,6 +105,12 @@ export function async_derived(fn, location) { // only suspend in async deriveds created on initialisation var should_suspend = !active_reaction; + var boundary = /** @type {Effect} */ (active_effect).b; + + while (boundary !== null && !boundary.has_pending_snippet()) { + boundary = boundary.parent; + } + render_effect(() => { if (DEV) from_async_derived = active_effect; promise = fn(); @@ -115,8 +121,16 @@ export function async_derived(fn, location) { var fork = active_fork; if (should_suspend) { - // TODO if nearest pending boundary is not ready, attach to the boundary - fork?.increment(); + 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(); + } } promise.then( @@ -129,7 +143,15 @@ export function async_derived(fn, location) { from_async_derived = null; if (should_suspend) { - fork?.decrement(); + if (fork !== null) { + fork.decrement(); + } else { + if (boundary === null) { + throw new Error('TODO'); + } + + boundary.decrement(); + } } if (fork !== null) { diff --git a/packages/svelte/tests/runtime-runes/samples/async-derived-module/_config.js b/packages/svelte/tests/runtime-runes/samples/async-derived-module/_config.js index 4631243cb2..b8e7e9b845 100644 --- a/packages/svelte/tests/runtime-runes/samples/async-derived-module/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/async-derived-module/_config.js @@ -26,6 +26,7 @@ export default test({ await Promise.resolve(); await Promise.resolve(); await Promise.resolve(); + await Promise.resolve(); flushSync(); await tick(); assert.htmlEqual(target.innerHTML, '

42

');