diff --git a/packages/svelte/src/internal/client/reactivity/deriveds.js b/packages/svelte/src/internal/client/reactivity/deriveds.js index 036256284c..3478784309 100644 --- a/packages/svelte/src/internal/client/reactivity/deriveds.js +++ b/packages/svelte/src/internal/client/reactivity/deriveds.js @@ -1,5 +1,6 @@ /** @import { Derived, Effect, Source } from '#client' */ /** @import { Batch } from './batch.js'; */ +/** @import { Boundary } from '../dom/blocks/boundary.js'; */ import { DEV } from 'esm-env'; import { ERROR_VALUE, @@ -145,11 +146,13 @@ export function async_derived(fn, label, location) { var batch = /** @type {Batch} */ (current_batch); - // we only increment the batch's pending state for updates, not creation, otherwise - // we will decrement to zero before the work that depends on this promise (e.g. a - // template effect) has initialized, causing the batch to resolve prematurely - if (should_suspend && (effect.f & REACTION_RAN) !== 0) { - var decrement_pending = increment_pending(); + if (should_suspend) { + // we only increment the batch's pending state for updates, not creation, otherwise + // we will decrement to zero before the work that depends on this promise (e.g. a + // template effect) has initialized, causing the batch to resolve prematurely + if ((effect.f & REACTION_RAN) !== 0) { + var decrement_pending = increment_pending(); + } if (/** @type {Boundary} */ (parent.b).is_rendered()) { deferreds.get(batch)?.reject(STALE_REACTION);