@@ -8,13 +8,7 @@ import {
88 set_hydrating
99} from '../hydration.js' ;
1010import { create_text , get_first_child } from '../operations.js' ;
11- import {
12- block ,
13- branch ,
14- destroy_effect ,
15- pause_effect ,
16- resume_effect
17- } from '../../reactivity/effects.js' ;
11+ import { block , teardown } from '../../reactivity/effects.js' ;
1812import { set_should_intro } from '../../render.js' ;
1913import { current_each_item , set_current_each_item } from './each.js' ;
2014import { active_effect } from '../../runtime.js' ;
@@ -23,6 +17,7 @@ import { DEV } from 'esm-env';
2317import { EFFECT_TRANSPARENT , ELEMENT_NODE } from '#client/constants' ;
2418import { assign_nodes } from '../template.js' ;
2519import { is_raw_text_element } from '../../../../utils.js' ;
20+ import { BranchManager } from './branches.js' ;
2621
2722/**
2823 * @param {Comment | Element } node
@@ -42,12 +37,6 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
4237
4338 var filename = DEV && location && component_context ?. function [ FILENAME ] ;
4439
45- /** @type {string | null } */
46- var tag ;
47-
48- /** @type {string | null } */
49- var current_tag ;
50-
5140 /** @type {null | Element } */
5241 var element = null ;
5342
@@ -58,46 +47,31 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
5847
5948 var anchor = /** @type {TemplateNode } */ ( hydrating ? hydrate_node : node ) ;
6049
61- /** @type {Effect | null } */
62- var effect ;
63-
6450 /**
6551 * The keyed `{#each ...}` item block, if any, that this element is inside.
6652 * We track this so we can set it when changing the element, allowing any
6753 * `animate:` directive to bind itself to the correct block
6854 */
6955 var each_item_block = current_each_item ;
7056
57+ var branches = new BranchManager ( anchor , false ) ;
58+
7159 block ( ( ) => {
7260 const next_tag = get_tag ( ) || null ;
7361 var ns = get_namespace ? get_namespace ( ) : is_svg || next_tag === 'svg' ? NAMESPACE_SVG : null ;
7462
75- // Assumption: Noone changes the namespace but not the tag (what would that even mean?)
76- if ( next_tag === tag ) return ;
77-
78- // See explanation of `each_item_block` above
79- var previous_each_item = current_each_item ;
80- set_current_each_item ( each_item_block ) ;
81-
82- if ( effect ) {
83- if ( next_tag === null ) {
84- // start outro
85- pause_effect ( effect , ( ) => {
86- effect = null ;
87- current_tag = null ;
88- } ) ;
89- } else if ( next_tag === current_tag ) {
90- // same tag as is currently rendered — abort outro
91- resume_effect ( effect ) ;
92- } else {
93- // tag is changing — destroy immediately, render contents without intro transitions
94- destroy_effect ( effect ) ;
95- set_should_intro ( false ) ;
96- }
63+ if ( next_tag === null ) {
64+ branches . ensure ( null , null ) ;
65+ set_should_intro ( true ) ;
66+ return ;
9767 }
9868
99- if ( next_tag && next_tag !== current_tag ) {
100- effect = branch ( ( ) => {
69+ branches . ensure ( next_tag , ( anchor ) => {
70+ // See explanation of `each_item_block` above
71+ var previous_each_item = current_each_item ;
72+ set_current_each_item ( each_item_block ) ;
73+
74+ if ( next_tag ) {
10175 element = hydrating
10276 ? /** @type {Element } */ ( element )
10377 : ns
@@ -149,16 +123,31 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
149123 /** @type {Effect } */ ( active_effect ) . nodes_end = element ;
150124
151125 anchor . before ( element ) ;
152- } ) ;
153- }
126+ }
127+
128+ set_current_each_item ( previous_each_item ) ;
129+
130+ if ( hydrating ) {
131+ set_hydrate_node ( anchor ) ;
132+ }
133+ } ) ;
154134
155- tag = next_tag ;
156- if ( tag ) current_tag = tag ;
135+ // revert to the default state after the effect has been created
157136 set_should_intro ( true ) ;
158137
159- set_current_each_item ( previous_each_item ) ;
138+ return ( ) => {
139+ if ( next_tag ) {
140+ // if we're in this callback because we're re-running the effect,
141+ // disable intros (unless no element is currently displayed)
142+ set_should_intro ( false ) ;
143+ }
144+ } ;
160145 } , EFFECT_TRANSPARENT ) ;
161146
147+ teardown ( ( ) => {
148+ set_should_intro ( true ) ;
149+ } ) ;
150+
162151 if ( was_hydrating ) {
163152 set_hydrating ( true ) ;
164153 set_hydrate_node ( anchor ) ;
0 commit comments