From 90310081f5a39c3831613e067ee5aad119e8eb0e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 23 Mar 2024 12:09:40 -0400 Subject: [PATCH] add note, simplify --- .../client/dom/blocks/svelte-element.js | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/svelte/src/internal/client/dom/blocks/svelte-element.js b/packages/svelte/src/internal/client/dom/blocks/svelte-element.js index a9bef19f66..225721e0ff 100644 --- a/packages/svelte/src/internal/client/dom/blocks/svelte-element.js +++ b/packages/svelte/src/internal/client/dom/blocks/svelte-element.js @@ -111,19 +111,18 @@ export function element(anchor, get_tag, is_svg, render_fn) { : document.createElement(next_tag); if (render_fn) { - let anchor; - - if (hydrating) { - // Use the existing ssr comment as the anchor so that the inner open and close - // methods can pick up the existing nodes correctly - anchor = /** @type {Comment} */ (element.firstChild); - } else { - anchor = empty(); - element.appendChild(anchor); - } - - if (anchor) { - render_fn(element, anchor); + // If hydrating, use the existing ssr comment as the anchor so that the + // inner open and close methods can pick up the existing nodes correctly + var child_anchor = hydrating + ? /** @type {Comment} */ (element.firstChild) + : element.appendChild(empty()); + + if (child_anchor) { + // `child_anchor` can be undefined if this is a void element with children, + // i.e. `...`. This is + // user error, but we warn on it elsewhere (in dev) so here we just + // silently ignore it + render_fn(element, child_anchor); } }