Skip to content

Commit a008a9b

Browse files
committed
simplify close_template
1 parent 45cc648 commit a008a9b

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export function svg_template_with_script(svg, return_fragment) {
9191
function open_template(is_fragment, use_clone_node, anchor, template_element_fn) {
9292
if (hydrating) {
9393
if (anchor !== null) {
94+
// TODO why is this sometimes null and sometimes not? needs clear documentation
9495
hydrate_block_anchor(anchor);
9596
}
9697

@@ -171,28 +172,28 @@ export function comment(anchor) {
171172
/**
172173
* Assign the created (or in hydration mode, traversed) dom elements to the current block
173174
* and insert the elements into the dom (in client mode).
174-
* @param {Element | Text} dom
175+
* @param {import('#client').Dom} dom
175176
* @param {boolean} is_fragment
176177
* @param {null | Text | Comment | Element} anchor
177178
* @returns {import('#client').Dom}
178179
*/
179180
function close_template(dom, is_fragment, anchor) {
180-
/** @type {import('#client').Dom} */
181-
var current = is_fragment
182-
? hydrating
183-
? // if hydrating, `dom` is already an array of nodes
184-
dom
185-
: // otherwise we need to create an array to store it on the current effect
186-
/** @type {import('#client').TemplateNode[]} */ (Array.from(dom.childNodes))
187-
: dom;
188-
189-
if (!hydrating && anchor !== null) {
190-
insert(current, anchor);
181+
if (!hydrating) {
182+
if (is_fragment) {
183+
// if hydrating, `dom` is already an array of nodes, but if not then
184+
// we need to create an array to store it on the current effect
185+
dom = /** @type {import('#client').Dom} */ (Array.from(/** @type {Node} */ (dom).childNodes));
186+
}
187+
188+
if (anchor !== null) {
189+
// TODO as with `open_template — why is this sometimes null and sometimes not?
190+
insert(dom, anchor);
191+
}
191192
}
192193

193-
/** @type {import('#client').Effect} */ (current_effect).dom = current;
194+
/** @type {import('#client').Effect} */ (current_effect).dom = dom;
194195

195-
return current;
196+
return dom;
196197
}
197198

198199
/**

0 commit comments

Comments
 (0)