From 4284067f28e5bd210aec6c8bd1f014014e0df25c Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Tue, 25 Jun 2024 17:37:33 +0100 Subject: [PATCH] tune --- .../src/internal/client/dom/blocks/each.js | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/svelte/src/internal/client/dom/blocks/each.js b/packages/svelte/src/internal/client/dom/blocks/each.js index 57e8d71180..99c17d70b6 100644 --- a/packages/svelte/src/internal/client/dom/blocks/each.js +++ b/packages/svelte/src/internal/client/dom/blocks/each.js @@ -482,11 +482,10 @@ function create_item(anchor, prev, next, value, key, index, render_fn, flags) { /** * @param {import('#client').TemplateNode} dom - * @param {import('#client').TemplateNode | null} sibling * @param {import("#client").Effect} effect * @returns {import('#client').TemplateNode} */ -function get_adjusted_first_node(dom, sibling, effect) { +function get_adjusted_first_node(dom, effect) { if ((dom.nodeType === 3 && /** @type {Text} */ (dom).data === '') || dom.nodeType === 8) { var adjusted = effect.first; var next; @@ -499,11 +498,7 @@ function get_adjusted_first_node(dom, sibling, effect) { } adjusted = next; } - var adjusted_dom = get_first_node(/** @type {import("#client").Effect} */ (adjusted)); - // If we have a sibling that contains the adjusted_dom, then use that instead. - if (sibling?.contains(adjusted_dom)) { - return sibling; - } + return get_first_node(/** @type {import("#client").Effect} */ (adjusted)); } return dom; } @@ -516,13 +511,12 @@ function get_adjusted_first_node(dom, sibling, effect) { function get_first_node(effect) { var dom = effect.dom; if (is_array(dom)) { - return get_adjusted_first_node(dom[0], dom[1], effect); + var adjusted_dom = get_adjusted_first_node(dom[0], effect); + // If we have a sibling that contains the adjusted_dom, then use that instead. + var sibling = dom[1]; + return sibling?.contains(adjusted_dom) ? sibling : adjusted_dom; } - return get_adjusted_first_node( - /** @type {import('#client').TemplateNode} **/ (dom), - null, - effect - ); + return get_adjusted_first_node(/** @type {import('#client').TemplateNode} **/ (dom), effect); } /**