diff --git a/packages/svelte/src/internal/client/dom/blocks/if.js b/packages/svelte/src/internal/client/dom/blocks/if.js index 164cd7ea60..d6001bab86 100644 --- a/packages/svelte/src/internal/client/dom/blocks/if.js +++ b/packages/svelte/src/internal/client/dom/blocks/if.js @@ -29,10 +29,8 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn) /** @type {boolean | null} */ let condition = null; - let mounted = false; - render_effect(() => { - if (condition === (condition = condition_fn())) return; + if (condition === (condition = !!condition_fn())) return; if (hydrating) { const comment_text = /** @type {Comment} */ (current_hydration_fragment?.[0])?.data; @@ -56,7 +54,7 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn) if (consequent_effect) { resume_effect(consequent_effect); } else { - consequent_effect = render_effect(() => consequent_fn(anchor_node)); + consequent_effect = render_effect(() => consequent_fn(anchor_node), {}, true); } if (alternate_effect) { @@ -68,7 +66,7 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn) if (alternate_effect) { resume_effect(alternate_effect); } else { - alternate_effect = alternate_fn && render_effect(() => alternate_fn(anchor_node)); + alternate_effect = alternate_fn && render_effect(() => alternate_fn(anchor_node), {}, true); } if (consequent_effect) { @@ -78,6 +76,4 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn) } } }); - - mounted = true; } diff --git a/packages/svelte/src/internal/client/reactivity/computations.js b/packages/svelte/src/internal/client/reactivity/computations.js index 30ec4fcb69..cec1ce6799 100644 --- a/packages/svelte/src/internal/client/reactivity/computations.js +++ b/packages/svelte/src/internal/client/reactivity/computations.js @@ -19,8 +19,10 @@ import { DERIVED, UNOWNED, CLEAN, - UNINITIALIZED + UNINITIALIZED, + INERT } from '../constants.js'; +import { noop } from '../../common.js'; /** * @template V @@ -263,8 +265,20 @@ export function derived_safe_equal(fn) { * @param {() => void} done */ export function pause_effect(effect, done) { - // TODO pause children - remove(effect.dom); + if (effect.r) { + for (const child of effect.r) { + pause_effect(child, noop); + } + } + + effect.f |= INERT; + + // TODO distinguish between 'block effects' (?) which own their own DOM + // and other render effects + if (effect.dom) { + remove(effect.dom); + } + done(); // TODO defer until transitions have completed }