Skip to content

Commit 9031008

Browse files
committed
add note, simplify
1 parent e18e5d2 commit 9031008

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

packages/svelte/src/internal/client/dom/blocks/svelte-element.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,18 @@ export function element(anchor, get_tag, is_svg, render_fn) {
111111
: document.createElement(next_tag);
112112

113113
if (render_fn) {
114-
let anchor;
115-
116-
if (hydrating) {
117-
// Use the existing ssr comment as the anchor so that the inner open and close
118-
// methods can pick up the existing nodes correctly
119-
anchor = /** @type {Comment} */ (element.firstChild);
120-
} else {
121-
anchor = empty();
122-
element.appendChild(anchor);
123-
}
124-
125-
if (anchor) {
126-
render_fn(element, anchor);
114+
// If hydrating, use the existing ssr comment as the anchor so that the
115+
// inner open and close methods can pick up the existing nodes correctly
116+
var child_anchor = hydrating
117+
? /** @type {Comment} */ (element.firstChild)
118+
: element.appendChild(empty());
119+
120+
if (child_anchor) {
121+
// `child_anchor` can be undefined if this is a void element with children,
122+
// i.e. `<svelte:element this={"hr"}>...</svelte:element>`. This is
123+
// user error, but we warn on it elsewhere (in dev) so here we just
124+
// silently ignore it
125+
render_fn(element, child_anchor);
127126
}
128127
}
129128

0 commit comments

Comments
 (0)