Skip to content

Commit cb7e6bc

Browse files
committed
simplify space_frag
1 parent 6bcaa6b commit cb7e6bc

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,23 @@ export function open_frag(template_element_fn, use_clone_node = true) {
115115
return open_template(true, use_clone_node, template_element_fn);
116116
}
117117

118-
const space_template = template(' ', false);
119118
const comment_template = template('<!>', true);
120119

121120
/**
122-
* @param {Text | Comment | Element | null} anchor
121+
* @param {Text | Comment | Element} anchor
123122
*/
124123
/*#__NO_SIDE_EFFECTS__*/
125124
export function space_frag(anchor) {
126-
/** @type {Node | null} */
127-
var node = /** @type {any} */ (open(space_template));
128-
// if an {expression} is empty during SSR, there might be no
129-
// text node to hydrate (or an anchor comment is falsely detected instead)
130-
// — we must therefore create one
131-
if (hydrating && node?.nodeType !== 3) {
132-
node = empty();
133-
// @ts-ignore in this case the anchor should always be a comment,
134-
// if not something more fundamental is wrong and throwing here is better to bail out early
135-
anchor.before(node);
125+
if (!hydrating) return empty();
126+
127+
var node = hydrate_nodes[0];
128+
129+
if (!node) {
130+
// if an {expression} is empty during SSR, `hydrate_nodes` will be empty.
131+
// we need to insert an empty text node
132+
anchor.before((node = empty()));
136133
}
134+
137135
return node;
138136
}
139137

0 commit comments

Comments
 (0)