Skip to content

Commit 52c24d2

Browse files
committed
tidy up
1 parent 512ae90 commit 52c24d2

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

packages/svelte/src/internal/client/dom/operations.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,14 @@ export function empty() {
123123
/*#__NO_SIDE_EFFECTS__*/
124124
export function child(node) {
125125
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());
135131
}
136-
return child;
132+
133+
return capture_fragment_from_node(child);
137134
}
138135

139136
/**
@@ -144,26 +141,26 @@ export function child(node) {
144141
*/
145142
/*#__NO_SIDE_EFFECTS__*/
146143
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+
}
149147

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];
158149

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+
}
162158

163-
return first_node;
159+
if (first_node !== null) {
160+
return capture_fragment_from_node(first_node);
164161
}
165162

166-
return first_child_get.call(/** @type {Node} */ (node));
163+
return first_node;
167164
}
168165

169166
/**
@@ -175,6 +172,7 @@ export function child_frag(node, is_text) {
175172
/*#__NO_SIDE_EFFECTS__*/
176173
export function sibling(node, is_text = false) {
177174
const next_sibling = next_sibling_get.call(node);
175+
178176
if (hydrating) {
179177
// if a sibling {expression} is empty during SSR, there might be no
180178
// text node to hydrate — we must therefore create one
@@ -183,7 +181,7 @@ export function sibling(node, is_text = false) {
183181
if (next_sibling) {
184182
const index = hydrate_nodes.indexOf(/** @type {Text | Comment | Element} */ (next_sibling));
185183
hydrate_nodes.splice(index, 0, text);
186-
/** @type {DocumentFragment} */ (next_sibling.parentNode).insertBefore(text, next_sibling);
184+
next_sibling.before(text);
187185
} else {
188186
hydrate_nodes.push(text);
189187
}
@@ -195,6 +193,7 @@ export function sibling(node, is_text = false) {
195193
return capture_fragment_from_node(next_sibling);
196194
}
197195
}
196+
198197
return next_sibling;
199198
}
200199

0 commit comments

Comments
 (0)