@@ -123,17 +123,14 @@ export function empty() {
123
123
/*#__NO_SIDE_EFFECTS__*/
124
124
export function child ( node ) {
125
125
const child = first_child_get . call ( node ) ;
126
- if ( hydrating ) {
127
- // Child can be null if we have an element with a single child, like `<p>{text}</p>`, where `text` is empty
128
- if ( child === null ) {
129
- const text = empty ( ) ;
130
- node . appendChild ( text ) ;
131
- return text ;
132
- } else {
133
- return capture_fragment_from_node ( child ) ;
134
- }
126
+ if ( ! hydrating ) return child ;
127
+
128
+ // Child can be null if we have an element with a single child, like `<p>{text}</p>`, where `text` is empty
129
+ if ( child === null ) {
130
+ return node . appendChild ( empty ( ) ) ;
135
131
}
136
- return child ;
132
+
133
+ return capture_fragment_from_node ( child ) ;
137
134
}
138
135
139
136
/**
@@ -144,26 +141,26 @@ export function child(node) {
144
141
*/
145
142
/*#__NO_SIDE_EFFECTS__*/
146
143
export function child_frag ( node , is_text ) {
147
- if ( hydrating ) {
148
- const first_node = /** @type {import('#client').TemplateNode[] } */ ( node ) [ 0 ] ;
144
+ if ( ! hydrating ) {
145
+ return first_child_get . call ( /** @type {Node } */ ( node ) ) ;
146
+ }
149
147
150
- // if an {expression} is empty during SSR, there might be no
151
- // text node to hydrate — we must therefore create one
152
- if ( is_text && first_node ?. nodeType !== 3 ) {
153
- const text = empty ( ) ;
154
- hydrate_nodes . unshift ( text ) ;
155
- first_node ?. before ( text ) ;
156
- return text ;
157
- }
148
+ const first_node = /** @type {import('#client').TemplateNode[] } */ ( node ) [ 0 ] ;
158
149
159
- if ( first_node !== null ) {
160
- return capture_fragment_from_node ( first_node ) ;
161
- }
150
+ // if an {expression} is empty during SSR, there might be no
151
+ // text node to hydrate — we must therefore create one
152
+ if ( is_text && first_node ?. nodeType !== 3 ) {
153
+ const text = empty ( ) ;
154
+ hydrate_nodes . unshift ( text ) ;
155
+ first_node ?. before ( text ) ;
156
+ return text ;
157
+ }
162
158
163
- return first_node ;
159
+ if ( first_node !== null ) {
160
+ return capture_fragment_from_node ( first_node ) ;
164
161
}
165
162
166
- return first_child_get . call ( /** @type { Node } */ ( node ) ) ;
163
+ return first_node ;
167
164
}
168
165
169
166
/**
@@ -175,6 +172,7 @@ export function child_frag(node, is_text) {
175
172
/*#__NO_SIDE_EFFECTS__*/
176
173
export function sibling ( node , is_text = false ) {
177
174
const next_sibling = next_sibling_get . call ( node ) ;
175
+
178
176
if ( hydrating ) {
179
177
// if a sibling {expression} is empty during SSR, there might be no
180
178
// text node to hydrate — we must therefore create one
@@ -183,7 +181,7 @@ export function sibling(node, is_text = false) {
183
181
if ( next_sibling ) {
184
182
const index = hydrate_nodes . indexOf ( /** @type {Text | Comment | Element } */ ( next_sibling ) ) ;
185
183
hydrate_nodes . splice ( index , 0 , text ) ;
186
- /** @type { DocumentFragment } */ ( next_sibling . parentNode ) . insertBefore ( text , next_sibling ) ;
184
+ next_sibling . before ( text ) ;
187
185
} else {
188
186
hydrate_nodes . push ( text ) ;
189
187
}
@@ -195,6 +193,7 @@ export function sibling(node, is_text = false) {
195
193
return capture_fragment_from_node ( next_sibling ) ;
196
194
}
197
195
}
196
+
198
197
return next_sibling ;
199
198
}
200
199
0 commit comments