fix: ensure hydration walks all nodes (#12448)

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
pull/12443/head
Simon H 4 months ago committed by GitHub
parent 141e3e9f92
commit da6e192e1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure hydration walks all nodes

@ -51,11 +51,11 @@ export function empty() {
}
/**
* Don't mark this as side-effect-free, hydration needs to walk all nodes
* @template {Node} N
* @param {N} node
* @returns {Node | null}
*/
/*#__NO_SIDE_EFFECTS__*/
export function child(node) {
if (!hydrating) {
return node.firstChild;
@ -73,11 +73,11 @@ export function child(node) {
}
/**
* Don't mark this as side-effect-free, hydration needs to walk all nodes
* @param {DocumentFragment | TemplateNode[]} fragment
* @param {boolean} is_text
* @returns {Node | null}
*/
/*#__NO_SIDE_EFFECTS__*/
export function first_child(fragment, is_text) {
if (!hydrating) {
// when not hydrating, `fragment` is a `DocumentFragment` (the result of calling `open_frag`)
@ -103,12 +103,12 @@ export function first_child(fragment, is_text) {
}
/**
* Don't mark this as side-effect-free, hydration needs to walk all nodes
* @template {Node} N
* @param {N} node
* @param {boolean} is_text
* @returns {Node | null}
*/
/*#__NO_SIDE_EFFECTS__*/
export function sibling(node, is_text = false) {
if (!hydrating) {
return /** @type {TemplateNode} */ (node.nextSibling);

@ -207,7 +207,9 @@ function run_scripts(node) {
}
}
/*#__NO_SIDE_EFFECTS__*/
/**
* Don't mark this as side-effect-free, hydration needs to walk all nodes
*/
export function text() {
if (!hydrating) {
var t = empty();

Loading…
Cancel
Save