Skip to content

Commit 15dc6ec

Browse files
committed
fix: ensure hydration walks all nodes
We've marked several methods used for walking the DOM with a `__NO_SIDE_EFFECTS__` comment. That was good historically, because we didn't need those kept around if its results were unused, but since the hydration changes in #12335 this actually introduces a bug: Because that PR now relies on the hydration nodes being correct due to walking the DOM, tree-shaking unused variables/calls results in the walk being incorrect, leading to bugs Fixes #12422
1 parent a8dc96e commit 15dc6ec

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

.changeset/giant-jars-applaud.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure hydration walks all nodes

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ export function empty() {
5151
}
5252

5353
/**
54+
* Don't mark this as side-effect-free, hydration needs to walk all nodes
5455
* @template {Node} N
5556
* @param {N} node
5657
* @returns {Node | null}
5758
*/
58-
/*#__NO_SIDE_EFFECTS__*/
5959
export function child(node) {
6060
if (!hydrating) {
6161
return node.firstChild;
@@ -73,11 +73,11 @@ export function child(node) {
7373
}
7474

7575
/**
76+
* Don't mark this as side-effect-free, hydration needs to walk all nodes
7677
* @param {DocumentFragment | TemplateNode[]} fragment
7778
* @param {boolean} is_text
7879
* @returns {Node | null}
7980
*/
80-
/*#__NO_SIDE_EFFECTS__*/
8181
export function first_child(fragment, is_text) {
8282
if (!hydrating) {
8383
// when not hydrating, `fragment` is a `DocumentFragment` (the result of calling `open_frag`)
@@ -103,12 +103,12 @@ export function first_child(fragment, is_text) {
103103
}
104104

105105
/**
106+
* Don't mark this as side-effect-free, hydration needs to walk all nodes
106107
* @template {Node} N
107108
* @param {N} node
108109
* @param {boolean} is_text
109110
* @returns {Node | null}
110111
*/
111-
/*#__NO_SIDE_EFFECTS__*/
112112
export function sibling(node, is_text = false) {
113113
if (!hydrating) {
114114
return /** @type {TemplateNode} */ (node.nextSibling);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ function run_scripts(node) {
207207
}
208208
}
209209

210-
/*#__NO_SIDE_EFFECTS__*/
210+
/**
211+
* Don't mark this as side-effect-free, hydration needs to walk all nodes
212+
*/
211213
export function text() {
212214
if (!hydrating) {
213215
var t = empty();

0 commit comments

Comments
 (0)