11/** @import { Effect, TemplateNode } from '#client' */
22import { FILENAME , HYDRATION_ERROR } from '../../../../constants.js' ;
3- import { branch , destroy_effect , template_effect } from '../../reactivity/effects.js' ;
3+ import { remove_effect_dom , template_effect } from '../../reactivity/effects.js' ;
44import { hydrate_next , hydrate_node , hydrating , set_hydrate_node } from '../hydration.js' ;
55import { create_fragment_from_html } from '../reconciler.js' ;
66import { assign_nodes } from '../template.js' ;
@@ -9,6 +9,7 @@ import { hash, sanitize_location } from '../../../../utils.js';
99import { DEV } from 'esm-env' ;
1010import { dev_current_component_function } from '../../context.js' ;
1111import { get_first_child , get_next_sibling } from '../operations.js' ;
12+ import { active_effect } from '../../runtime.js' ;
1213
1314/**
1415 * @param {Element } element
@@ -44,77 +45,71 @@ export function html(node, get_value, svg = false, mathml = false, skip_warning
4445
4546 var value = '' ;
4647
47- /** @type {Effect | undefined } */
48- var effect ;
49-
5048 template_effect ( ( ) => {
49+ var effect = /** @type {Effect } */ ( active_effect ) ;
50+
5151 if ( value === ( value = get_value ( ) ?? '' ) ) {
5252 if ( hydrating ) hydrate_next ( ) ;
5353 return ;
5454 }
5555
56- if ( effect !== undefined ) {
57- destroy_effect ( effect ) ;
58- effect = undefined ;
56+ if ( effect . nodes_start !== null ) {
57+ remove_effect_dom ( effect . nodes_start , /** @type { TemplateNode } */ ( effect . nodes_end ) ) ;
58+ effect . nodes_start = effect . nodes_end = null ;
5959 }
6060
6161 if ( value === '' ) return ;
6262
63- effect = branch ( ( ) => {
64- if ( hydrating ) {
65- // We're deliberately not trying to repair mismatches between server and client,
66- // as it's costly and error-prone (and it's an edge case to have a mismatch anyway)
67- var hash = /** @type {Comment } */ ( hydrate_node ) . data ;
68- var next = hydrate_next ( ) ;
69- var last = next ;
70-
71- while (
72- next !== null &&
73- ( next . nodeType !== 8 || /** @type {Comment } */ ( next ) . data !== '' )
74- ) {
75- last = next ;
76- next = /** @type {TemplateNode } */ ( get_next_sibling ( next ) ) ;
77- }
78-
79- if ( next === null ) {
80- w . hydration_mismatch ( ) ;
81- throw HYDRATION_ERROR ;
82- }
83-
84- if ( DEV && ! skip_warning ) {
85- check_hash ( /** @type {Element } */ ( next . parentNode ) , hash , value ) ;
86- }
87-
88- assign_nodes ( hydrate_node , last ) ;
89- anchor = set_hydrate_node ( next ) ;
90- return ;
91- }
63+ if ( hydrating ) {
64+ // We're deliberately not trying to repair mismatches between server and client,
65+ // as it's costly and error-prone (and it's an edge case to have a mismatch anyway)
66+ var hash = /** @type {Comment } */ ( hydrate_node ) . data ;
67+ var next = hydrate_next ( ) ;
68+ var last = next ;
9269
93- var html = value + '' ;
94- if ( svg ) html = `<svg>${ html } </svg>` ;
95- else if ( mathml ) html = `<math>${ html } </math>` ;
70+ while ( next !== null && ( next . nodeType !== 8 || /** @type {Comment } */ ( next ) . data !== '' ) ) {
71+ last = next ;
72+ next = /** @type {TemplateNode } */ ( get_next_sibling ( next ) ) ;
73+ }
9674
97- // Don't use create_fragment_with_script_from_html here because that would mean script tags are executed.
98- // @html is basically `.innerHTML = ...` and that doesn't execute scripts either due to security reasons.
99- /** @type { DocumentFragment | Element } */
100- var node = create_fragment_from_html ( html ) ;
75+ if ( next === null ) {
76+ w . hydration_mismatch ( ) ;
77+ throw HYDRATION_ERROR ;
78+ }
10179
102- if ( svg || mathml ) {
103- node = /** @type {Element } */ ( get_first_child ( node ) ) ;
80+ if ( DEV && ! skip_warning ) {
81+ check_hash ( /** @type {Element } */ ( next . parentNode ) , hash , value ) ;
10482 }
10583
106- assign_nodes (
107- /** @type {TemplateNode } */ ( get_first_child ( node ) ) ,
108- /** @type {TemplateNode } */ ( node . lastChild )
109- ) ;
110-
111- if ( svg || mathml ) {
112- while ( get_first_child ( node ) ) {
113- anchor . before ( /** @type {Node } */ ( get_first_child ( node ) ) ) ;
114- }
115- } else {
116- anchor . before ( node ) ;
84+ assign_nodes ( hydrate_node , last ) ;
85+ anchor = set_hydrate_node ( next ) ;
86+ return ;
87+ }
88+
89+ var html = value + '' ;
90+ if ( svg ) html = `<svg>${ html } </svg>` ;
91+ else if ( mathml ) html = `<math>${ html } </math>` ;
92+
93+ // Don't use create_fragment_with_script_from_html here because that would mean script tags are executed.
94+ // @html is basically `.innerHTML = ...` and that doesn't execute scripts either due to security reasons.
95+ /** @type {DocumentFragment | Element } */
96+ var node = create_fragment_from_html ( html ) ;
97+
98+ if ( svg || mathml ) {
99+ node = /** @type {Element } */ ( get_first_child ( node ) ) ;
100+ }
101+
102+ assign_nodes (
103+ /** @type {TemplateNode } */ ( get_first_child ( node ) ) ,
104+ /** @type {TemplateNode } */ ( node . lastChild )
105+ ) ;
106+
107+ if ( svg || mathml ) {
108+ while ( get_first_child ( node ) ) {
109+ anchor . before ( /** @type {Node } */ ( get_first_child ( node ) ) ) ;
117110 }
118- } ) ;
111+ } else {
112+ anchor . before ( node ) ;
113+ }
119114 } ) ;
120115}
0 commit comments