@ -10,7 +10,7 @@ import { current_block, execute_effect } from '../../runtime.js';
import { destroy _effect , render _effect } from '../../reactivity/effects.js' ;
import { destroy _effect , render _effect } from '../../reactivity/effects.js' ;
import { trigger _transitions } from '../elements/transitions.js' ;
import { trigger _transitions } from '../elements/transitions.js' ;
/** @returns {import(' ../../types.js ').IfBlock} */
/** @returns {import(' #client ').IfBlock} */
function create _if _block ( ) {
function create _if _block ( ) {
return {
return {
// alternate transitions
// alternate transitions
@ -26,7 +26,7 @@ function create_if_block() {
// effect
// effect
e : null ,
e : null ,
// parent
// parent
p : /** @type {import(' ../../types.js ').Block} */ ( current _block ) ,
p : /** @type {import(' #client ').Block} */ ( current _block ) ,
// transition
// transition
r : null ,
r : null ,
// type
// type
@ -45,137 +45,157 @@ function create_if_block() {
* /
* /
export function if _block ( anchor _node , condition _fn , consequent _fn , alternate _fn ) {
export function if _block ( anchor _node , condition _fn , consequent _fn , alternate _fn ) {
const block = create _if _block ( ) ;
const block = create _if _block ( ) ;
hydrate _block _anchor ( anchor _node ) ;
hydrate _block _anchor ( anchor _node ) ;
/** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
/** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
let mismatch = false ;
let mismatch = false ;
/** @type {null | import(' ../../types.js').TemplateNode | Array<import('../../types.js ').TemplateNode>} */
/** @type {null | import(' #client').TemplateNode | Array<import('#client ').TemplateNode>} */
let consequent _dom = null ;
let consequent _dom = null ;
/** @type {null | import('../../types.js').TemplateNode | Array<import('../../types.js').TemplateNode>} */
/** @type {null | import('#client').TemplateNode | Array<import('#client').TemplateNode>} */
let alternate _dom = null ;
let alternate _dom = null ;
let has _mounted = false ;
let has _mounted = false ;
/ * *
/ * *
* @ type { import ( ' ../../types.js ') . Effect | null }
* @ type { import ( ' #client ') . Effect | null }
* /
* /
let current _branch _effect = null ;
let current _branch _effect = null ;
const if _effect = render _effect (
/** @type {import('#client').Effect} */
( ) => {
let consequent _effect ;
const result = ! ! condition _fn ( ) ;
if ( block . v !== result || ! has _mounted ) {
/** @type {import('#client').Effect} */
block . v = resul t;
let alternate _effec t;
if ( has _mounted ) {
const consequent _transitions = block . c ;
const if _effect = render _effect ( ( ) => {
const alternate _transitions = block . a ;
const result = ! ! condition _fn ( ) ;
if ( result ) {
if ( alternate _transitions === null || alternate _transitions . size === 0 ) {
if ( block . v !== result || ! has _mounted ) {
execute _effect ( alternate _effect ) ;
block . v = result ;
} else {
trigger _transitions ( alternate _transitions , 'out' ) ;
if ( has _mounted ) {
}
const consequent _transitions = block . c ;
if ( consequent _transitions === null || consequent _transitions . size === 0 ) {
const alternate _transitions = block . a ;
execute _effect ( consequent _effect ) ;
} else {
if ( result ) {
trigger _transitions ( consequent _transitions , 'in' ) ;
if ( alternate _transitions === null || alternate _transitions . size === 0 ) {
}
execute _effect ( alternate _effect ) ;
} else {
} else {
if ( consequent _transitions === null || consequent _transitions . size === 0 ) {
trigger _transitions ( alternate _transitions , 'out' ) ;
execute _effect ( consequent _effect ) ;
} else {
trigger _transitions ( consequent _transitions , 'out' ) ;
}
if ( alternate _transitions === null || alternate _transitions . size === 0 ) {
execute _effect ( alternate _effect ) ;
} else {
trigger _transitions ( alternate _transitions , 'in' ) ;
}
}
}
} else if ( hydrating ) {
const comment _text = /** @type {Comment} */ ( current _hydration _fragment ? . [ 0 ] ) ? . data ;
if ( consequent _transitions === null || consequent _transitions . size === 0 ) {
if (
execute _effect ( consequent _effect ) ;
! comment _text ||
( comment _text === 'ssr:if:true' && ! result ) ||
( comment _text === 'ssr:if:false' && result )
) {
// Hydration mismatch: remove everything inside the anchor and start fresh.
// This could happen using when `{#if browser} .. {/if}` in SvelteKit.
remove ( current _hydration _fragment ) ;
set _current _hydration _fragment ( null ) ;
mismatch = true ;
} else {
} else {
// Remove the ssr:if comment node or else it will confuse the subsequent hydration algorithm
trigger _transitions ( consequent _transitions , 'in' ) ;
current _hydration _fragment . shift ( ) ;
}
} else {
if ( consequent _transitions === null || consequent _transitions . size === 0 ) {
execute _effect ( consequent _effect ) ;
} else {
trigger _transitions ( consequent _transitions , 'out' ) ;
}
if ( alternate _transitions === null || alternate _transitions . size === 0 ) {
execute _effect ( alternate _effect ) ;
} else {
trigger _transitions ( alternate _transitions , 'in' ) ;
}
}
}
}
has _mounted = true ;
} else if ( hydrating ) {
}
const comment _text = /** @type {Comment} */ ( current _hydration _fragment ? . [ 0 ] ) ? . data ;
} ,
block ,
if (
false
! comment _text ||
) ;
( comment _text === 'ssr:if:true' && ! result ) ||
// Managed effect
( comment _text === 'ssr:if:false' && result )
const consequent _effect = render _effect (
) {
(
// Hydration mismatch: remove everything inside the anchor and start fresh.
/** @type {any} */ _ ,
// This could happen using when `{#if browser} .. {/if}` in SvelteKit.
/** @type {import('../../types.js').Effect | null} */ consequent _effect
remove ( current _hydration _fragment ) ;
) => {
set _current _hydration _fragment ( null ) ;
const result = block . v ;
mismatch = true ;
if ( ! result && consequent _dom !== null ) {
} else {
remove ( consequent _dom ) ;
// Remove the ssr:if comment node or else it will confuse the subsequent hydration algorithm
consequent _dom = null ;
current _hydration _fragment . shift ( ) ;
}
if ( result && current _branch _effect !== consequent _effect ) {
consequent _fn ( anchor _node ) ;
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 ;
}
}
block . d = null ;
} ,
has _mounted = true ;
block ,
}
true
) ;
// create these here so they have the correct parent/child relationship
block . ce = consequent _effect ;
consequent _effect ? ? = render _effect (
// Managed effect
( /** @type {any} */ _ , /** @type {import('#client').Effect | null} */ consequent _effect ) => {
const alternate _effect = render _effect (
const result = block . v ;
(
/** @type {any} */ _ ,
if ( ! result && consequent _dom !== null ) {
/** @type {import('../../types.js').Effect | null} */ alternate _effect
remove ( consequent _dom ) ;
) => {
consequent _dom = null ;
const result = block . v ;
}
if ( result && alternate _dom !== null ) {
remove ( alternate _dom ) ;
if ( result && current _branch _effect !== consequent _effect ) {
alternate _dom = null ;
consequent _fn ( anchor _node ) ;
}
if ( mismatch && current _branch _effect === null ) {
if ( ! result && current _branch _effect !== alternate _effect ) {
// Set fragment so that Svelte continues to operate in hydration mode
if ( alternate _fn !== null ) {
set _current _hydration _fragment ( [ ] ) ;
alternate _fn ( anchor _node ) ;
}
current _branch _effect = consequent _effect ;
consequent _dom = block . d ;
}
}
if ( mismatch && current _branch _effect === null ) {
// Set fragment so that Svelte continues to operate in hydration mode
block . d = null ;
set _current _hydration _fragment ( [ ] ) ;
} ,
block ,
true
) ;
block . ce = consequent _effect ;
alternate _effect ? ? = render _effect (
( /** @type {any} */ _ , /** @type {import('#client').Effect | null} */ alternate _effect ) => {
const result = block . v ;
if ( result && alternate _dom !== null ) {
remove ( alternate _dom ) ;
alternate _dom = null ;
}
}
current _branch _effect = alternate _effect ;
alternate _dom = block . d ;
if ( ! result && current _branch _effect !== alternate _effect ) {
}
if ( alternate _fn !== null ) {
block . d = null ;
alternate _fn ( anchor _node ) ;
} ,
}
block ,
true
if ( mismatch && current _branch _effect === null ) {
) ;
// Set fragment so that Svelte continues to operate in hydration mode
block . ae = alternate _effect ;
set _current _hydration _fragment ( [ ] ) ;
}
current _branch _effect = alternate _effect ;
alternate _dom = block . d ;
}
block . d = null ;
} ,
block ,
true
) ;
block . ae = alternate _effect ;
} , block ) ;
if _effect . ondestroy = ( ) => {
if _effect . ondestroy = ( ) => {
if ( consequent _dom !== null ) {
if ( consequent _dom !== null ) {
remove ( consequent _dom ) ;
remove ( consequent _dom ) ;
}
}
if ( alternate _dom !== null ) {
if ( alternate _dom !== null ) {
remove ( alternate _dom ) ;
remove ( alternate _dom ) ;
}
}
destroy _effect ( consequent _effect ) ;
destroy _effect ( consequent _effect ) ;
destroy _effect ( alternate _effect ) ;
destroy _effect ( alternate _effect ) ;
} ;
} ;
block . e = if _effect ;
block . e = if _effect ;
}
}