create correct parent-child relationship between if block and its branches

pull/10794/head
Rich Harris 2 years ago
parent 82275adea3
commit 0a7615fe1b

@ -127,67 +127,69 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn)
has_mounted = true; has_mounted = true;
} }
},
block,
false
);
// Managed effect // create these here so they have the correct parent/child relationship
consequent_effect = render_effect( consequent_effect ??= render_effect(
(/** @type {any} */ _, /** @type {import('#client').Effect | null} */ consequent_effect) => { (
const result = block.v; /** @type {any} */ _,
/** @type {import('#client').Effect | null} */ consequent_effect
) => {
const result = block.v;
if (!result && consequent_dom !== null) {
remove(consequent_dom);
consequent_dom = null;
}
if (!result && consequent_dom !== null) { if (result && current_branch_effect !== consequent_effect) {
remove(consequent_dom); consequent_fn(anchor_node);
consequent_dom = null; if (mismatch && current_branch_effect === null) {
} // Set fragment so that Svelte continues to operate in hydration mode
set_current_hydration_fragment([]);
}
current_branch_effect = consequent_effect;
consequent_dom = block.d;
}
if (result && current_branch_effect !== consequent_effect) { block.d = null;
consequent_fn(anchor_node); },
if (mismatch && current_branch_effect === null) { block,
// Set fragment so that Svelte continues to operate in hydration mode true
set_current_hydration_fragment([]); );
} block.ce = consequent_effect;
current_branch_effect = consequent_effect;
consequent_dom = block.d;
}
block.d = null; alternate_effect ??= render_effect(
}, (/** @type {any} */ _, /** @type {import('#client').Effect | null} */ alternate_effect) => {
block, const result = block.v;
true
);
block.ce = consequent_effect;
// Managed effect
alternate_effect = render_effect(
(/** @type {any} */ _, /** @type {import('#client').Effect | null} */ alternate_effect) => {
const result = block.v;
if (result && alternate_dom !== null) { if (result && alternate_dom !== null) {
remove(alternate_dom); remove(alternate_dom);
alternate_dom = null; alternate_dom = null;
} }
if (!result && current_branch_effect !== alternate_effect) { if (!result && current_branch_effect !== alternate_effect) {
if (alternate_fn !== null) { if (alternate_fn !== null) {
alternate_fn(anchor_node); alternate_fn(anchor_node);
} }
if (mismatch && current_branch_effect === null) { if (mismatch && current_branch_effect === null) {
// Set fragment so that Svelte continues to operate in hydration mode // Set fragment so that Svelte continues to operate in hydration mode
set_current_hydration_fragment([]); set_current_hydration_fragment([]);
} }
current_branch_effect = alternate_effect; current_branch_effect = alternate_effect;
alternate_dom = block.d; alternate_dom = block.d;
} }
block.d = null; block.d = null;
},
block,
true
);
block.ae = alternate_effect;
}, },
block, block,
true false
); );
block.ae = alternate_effect;
if_effect.ondestroy = () => { if_effect.ondestroy = () => {
if (consequent_dom !== null) { if (consequent_dom !== null) {

@ -786,25 +786,11 @@ export function mark_subtree_inert(signal, inert, visited_blocks = new Set()) {
if (!inert && (flags & CLEAN) === 0) { if (!inert && (flags & CLEAN) === 0) {
schedule_effect(signal, false); schedule_effect(signal, false);
} }
// Nested if block effects
const block = signal.block; const block = signal.block;
if (block !== null && !visited_blocks.has(block)) { if (block !== null && !visited_blocks.has(block)) {
visited_blocks.add(block); visited_blocks.add(block);
const type = block.t; if (block.t === EACH_BLOCK) {
if (type === IF_BLOCK) {
const condition_effect = block.e;
if (condition_effect !== null && block !== current_block) {
mark_subtree_inert(condition_effect, inert, visited_blocks);
}
const consequent_effect = block.ce;
if (consequent_effect !== null && block.v) {
mark_subtree_inert(consequent_effect, inert, visited_blocks);
}
const alternate_effect = block.ae;
if (alternate_effect !== null && !block.v) {
mark_subtree_inert(alternate_effect, inert, visited_blocks);
}
} else if (type === EACH_BLOCK) {
const items = block.v; const items = block.v;
for (let { e: each_item_effect } of items) { for (let { e: each_item_effect } of items) {
if (each_item_effect !== null) { if (each_item_effect !== null) {

Loading…
Cancel
Save