Skip to content

Commit d4b7168

Browse files
committed
chore: always return hydrate_start from template functions
1 parent c239cdf commit d4b7168

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hydrate_anchor, hydrating } from './hydration.js';
1+
import { hydrate_anchor, hydrate_start, hydrating } from './hydration.js';
22
import { DEV } from 'esm-env';
33
import { init_array_prototype_warnings } from '../dev/equality.js';
44
import { current_effect } from '../runtime.js';
@@ -96,24 +96,21 @@ export function first_child(fragment, is_text) {
9696
return /** @type {DocumentFragment} */ (fragment).firstChild;
9797
}
9898

99-
// when we _are_ hydrating, `fragment` is an array of nodes
100-
var first_node = /** @type {import('#client').TemplateNode[]} */ (fragment)[0];
101-
10299
// if an {expression} is empty during SSR, there might be no
103100
// text node to hydrate — we must therefore create one
104-
if (is_text && first_node?.nodeType !== 3) {
101+
if (is_text && hydrate_start?.nodeType !== 3) {
105102
var text = empty();
106103
var dom = /** @type {import('#client').TemplateNode[]} */ (
107104
/** @type {import('#client').Effect} */ (current_effect).dom
108105
);
109106

110107
dom.unshift(text);
111-
first_node?.before(text);
108+
hydrate_start?.before(text);
112109

113110
return text;
114111
}
115112

116-
return hydrate_anchor(first_node);
113+
return hydrate_anchor(hydrate_start);
117114
}
118115

119116
/**

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ import { effect } from '../reactivity/effects.js';
88
/**
99
* @template {import("#client").TemplateNode | import("#client").TemplateNode[]} T
1010
* @param {T} dom
11-
* @returns {T}
1211
*/
1312
function push_template_node(dom) {
1413
var effect = /** @type {import('#client').Effect} */ (current_effect);
1514

1615
if (effect.dom === null) {
1716
effect.dom = dom;
1817
}
19-
20-
return dom;
2118
}
2219

2320
/**
@@ -35,7 +32,8 @@ export function template(content, flags) {
3532

3633
return () => {
3734
if (hydrating) {
38-
return push_template_node(is_fragment ? hydrate_nodes : hydrate_start);
35+
push_template_node(is_fragment ? hydrate_nodes : hydrate_start);
36+
return hydrate_start;
3937
}
4038

4139
if (!node) {
@@ -87,7 +85,8 @@ export function ns_template(content, flags, ns = 'svg') {
8785

8886
return () => {
8987
if (hydrating) {
90-
return push_template_node(is_fragment ? hydrate_nodes : hydrate_start);
88+
push_template_node(is_fragment ? hydrate_nodes : hydrate_start);
89+
return hydrate_start;
9190
}
9291

9392
if (!node) {
@@ -188,14 +187,17 @@ export function text(anchor) {
188187
anchor.before((node = empty()));
189188
}
190189

191-
return push_template_node(node);
190+
push_template_node(node);
191+
return node;
192192
}
193193

194194
export function comment() {
195195
// we're not delegating to `template` here for performance reasons
196196
if (hydrating) {
197-
return push_template_node(hydrate_nodes);
197+
push_template_node(hydrate_nodes);
198+
return hydrate_start;
198199
}
200+
199201
var frag = document.createDocumentFragment();
200202
var anchor = empty();
201203
frag.append(anchor);

0 commit comments

Comments
 (0)