1
1
/** @import { Effect, TemplateNode } from '#client' */
2
2
import { FILENAME , HYDRATION_ERROR } from '../../../../constants.js' ;
3
- import { block , branch , destroy_effect } from '../../reactivity/effects.js' ;
3
+ import { remove_effect_dom , template_effect } from '../../reactivity/effects.js' ;
4
4
import { hydrate_next , hydrate_node , hydrating , set_hydrate_node } from '../hydration.js' ;
5
5
import { create_fragment_from_html } from '../reconciler.js' ;
6
6
import { assign_nodes } from '../template.js' ;
@@ -9,6 +9,7 @@ import { hash, sanitize_location } from '../../../../utils.js';
9
9
import { DEV } from 'esm-env' ;
10
10
import { dev_current_component_function } from '../../context.js' ;
11
11
import { get_first_child , get_next_sibling } from '../operations.js' ;
12
+ import { active_effect } from '../../runtime.js' ;
12
13
13
14
/**
14
15
* @param {Element } element
@@ -44,79 +45,71 @@ export function html(node, get_value, svg = false, mathml = false, skip_warning
44
45
45
46
var value = '' ;
46
47
47
- /** @type { Effect | undefined } */
48
- var effect ;
48
+ template_effect ( ( ) => {
49
+ var effect = /** @type { Effect } */ ( active_effect ) ;
49
50
50
- block ( ( ) => {
51
51
if ( value === ( value = get_value ( ) ?? '' ) ) {
52
- if ( hydrating ) {
53
- hydrate_next ( ) ;
54
- }
52
+ if ( hydrating ) hydrate_next ( ) ;
55
53
return ;
56
54
}
57
55
58
- if ( effect !== undefined ) {
59
- destroy_effect ( effect ) ;
60
- 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 ;
61
59
}
62
60
63
61
if ( value === '' ) return ;
64
62
65
- effect = branch ( ( ) => {
66
- if ( hydrating ) {
67
- // We're deliberately not trying to repair mismatches between server and client,
68
- // as it's costly and error-prone (and it's an edge case to have a mismatch anyway)
69
- var hash = /** @type {Comment } */ ( hydrate_node ) . data ;
70
- var next = hydrate_next ( ) ;
71
- var last = next ;
72
-
73
- while (
74
- next !== null &&
75
- ( next . nodeType !== 8 || /** @type {Comment } */ ( next ) . data !== '' )
76
- ) {
77
- last = next ;
78
- next = /** @type {TemplateNode } */ ( get_next_sibling ( next ) ) ;
79
- }
80
-
81
- if ( next === null ) {
82
- w . hydration_mismatch ( ) ;
83
- throw HYDRATION_ERROR ;
84
- }
85
-
86
- if ( DEV && ! skip_warning ) {
87
- check_hash ( /** @type {Element } */ ( next . parentNode ) , hash , value ) ;
88
- }
89
-
90
- assign_nodes ( hydrate_node , last ) ;
91
- anchor = set_hydrate_node ( next ) ;
92
- return ;
93
- }
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 ;
94
69
95
- var html = value + '' ;
96
- if ( svg ) html = `<svg>${ html } </svg>` ;
97
- 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
+ }
98
74
99
- // Don't use create_fragment_with_script_from_html here because that would mean script tags are executed.
100
- // @html is basically `.innerHTML = ...` and that doesn't execute scripts either due to security reasons.
101
- /** @type { DocumentFragment | Element } */
102
- var node = create_fragment_from_html ( html ) ;
75
+ if ( next === null ) {
76
+ w . hydration_mismatch ( ) ;
77
+ throw HYDRATION_ERROR ;
78
+ }
103
79
104
- if ( svg || mathml ) {
105
- node = /** @type {Element } */ ( get_first_child ( node ) ) ;
80
+ if ( DEV && ! skip_warning ) {
81
+ check_hash ( /** @type {Element } */ ( next . parentNode ) , hash , value ) ;
106
82
}
107
83
108
- assign_nodes (
109
- /** @type {TemplateNode } */ ( get_first_child ( node ) ) ,
110
- /** @type {TemplateNode } */ ( node . lastChild )
111
- ) ;
112
-
113
- if ( svg || mathml ) {
114
- while ( get_first_child ( node ) ) {
115
- anchor . before ( /** @type {Node } */ ( get_first_child ( node ) ) ) ;
116
- }
117
- } else {
118
- 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 ) ) ) ;
119
110
}
120
- } ) ;
111
+ } else {
112
+ anchor . before ( node ) ;
113
+ }
121
114
} ) ;
122
115
}
0 commit comments