From 2c4ceac0ec9a8b1c478744e54191997fa3ffb0aa Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 23 May 2024 17:04:50 -0400 Subject: [PATCH] manipulate effect.dom rather than hydrate_nodes --- .../src/internal/client/dom/operations.js | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/svelte/src/internal/client/dom/operations.js b/packages/svelte/src/internal/client/dom/operations.js index 7fd4ceac74..87c917d65f 100644 --- a/packages/svelte/src/internal/client/dom/operations.js +++ b/packages/svelte/src/internal/client/dom/operations.js @@ -1,6 +1,7 @@ import { hydrate_anchor, hydrate_nodes, hydrating } from './hydration.js'; import { DEV } from 'esm-env'; import { init_array_prototype_warnings } from '../dev/equality.js'; +import { current_effect } from '../runtime.js'; // We cache the Node and Element prototype methods, so that we can avoid doing // expensive prototype chain lookups. @@ -96,14 +97,19 @@ export function first_child(fragment, is_text) { } // when we _are_ hydrating, `fragment` is an array of nodes - const first_node = /** @type {import('#client').TemplateNode[]} */ (fragment)[0]; + var first_node = /** @type {import('#client').TemplateNode[]} */ (fragment)[0]; // if an {expression} is empty during SSR, there might be no // text node to hydrate — we must therefore create one if (is_text && first_node?.nodeType !== 3) { - const text = empty(); - hydrate_nodes.unshift(text); + var text = empty(); + var dom = /** @type {import('#client').TemplateNode[]} */ ( + /** @type {import('#client').Effect} */ (current_effect).dom + ); + + dom.unshift(text); first_node?.before(text); + return text; } @@ -127,14 +133,13 @@ export function sibling(node, is_text = false) { // if a sibling {expression} is empty during SSR, there might be no // text node to hydrate — we must therefore create one if (is_text && next_sibling?.nodeType !== 3) { - const text = empty(); - if (next_sibling) { - const index = hydrate_nodes.indexOf(/** @type {Text | Comment | Element} */ (next_sibling)); - hydrate_nodes.splice(index, 0, text); - next_sibling.before(text); - } else { - hydrate_nodes.push(text); - } + var text = empty(); + var dom = /** @type {import('#client').TemplateNode[]} */ ( + /** @type {import('#client').Effect} */ (current_effect).dom + ); + + dom.unshift(text); + next_sibling?.before(text); return text; }