22import { EFFECT_TRANSPARENT } from '#client/constants' ;
33import {
44 hydrate_next ,
5- hydrate_node ,
65 hydrating ,
76 read_hydration_instruction ,
87 skip_nodes ,
98 set_hydrate_node ,
109 set_hydrating
1110} from '../hydration.js' ;
1211import { block } from '../../reactivity/effects.js' ;
13- import { HYDRATION_START_ELSE , UNINITIALIZED } from '../../../../constants.js' ;
12+ import { HYDRATION_START_ELSE } from '../../../../constants.js' ;
1413import { BranchManager } from './branches.js' ;
1514import { noop } from '../../../shared/utils.js' ;
1615
@@ -27,54 +26,46 @@ export function if_block(node, fn, elseif = false) {
2726 hydrate_next ( ) ;
2827 }
2928
30- var anchor = node ;
31-
29+ var branches = new BranchManager ( node ) ;
3230 var flags = elseif ? EFFECT_TRANSPARENT : 0 ;
3331
34- var has_branch = false ;
35-
36- const set_branch = ( /** @type {(anchor: Node) => void } */ fn , flag = true ) => {
37- has_branch = true ;
38- update_branch ( flag , fn ) ;
39- } ;
40-
41- var branches = new BranchManager ( anchor ) ;
42-
43- const update_branch = (
44- /** @type {boolean } */ condition ,
45- /** @type {null | ((anchor: Node) => void) } */ fn
46- ) => {
32+ /**
33+ * @param {boolean } condition,
34+ * @param {((anchor: Node) => void) } fn
35+ */
36+ function update_branch ( condition , fn ) {
4737 if ( hydrating ) {
48- const is_else = read_hydration_instruction ( anchor ) === HYDRATION_START_ELSE ;
38+ const is_else = read_hydration_instruction ( node ) === HYDRATION_START_ELSE ;
4939
50- if ( ! ! condition === is_else ) {
40+ if ( condition === is_else ) {
5141 // Hydration mismatch: remove everything inside the anchor and start fresh.
5242 // This could happen with `{#if browser}...{/if}`, for example
53- anchor = skip_nodes ( ) ;
43+ var anchor = skip_nodes ( ) ;
5444
5545 set_hydrate_node ( anchor ) ;
5646 branches . anchor = anchor ;
5747
5848 set_hydrating ( false ) ;
59- branches . ensure ( condition , fn ?? noop ) ;
49+ branches . ensure ( condition , fn ) ;
6050 set_hydrating ( true ) ;
6151
6252 return ;
6353 }
6454 }
6555
66- branches . ensure ( condition , fn ?? noop ) ;
67- } ;
56+ branches . ensure ( condition , fn ) ;
57+ }
6858
6959 block ( ( ) => {
70- has_branch = false ;
71- fn ( set_branch ) ;
60+ var has_branch = false ;
61+
62+ fn ( ( fn , flag = true ) => {
63+ has_branch = true ;
64+ update_branch ( flag , fn ) ;
65+ } ) ;
66+
7267 if ( ! has_branch ) {
73- update_branch ( false , null ) ;
68+ update_branch ( false , noop ) ;
7469 }
7570 } , flags ) ;
76-
77- if ( hydrating ) {
78- anchor = hydrate_node ;
79- }
8071}
0 commit comments