-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Nodes appear out of order on hydration with 3.38.1 #6279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Having probably the same issue here, one braced expression is also duplicated on one of my components. Had to revert on 3.37. |
I think I've figured out the cause of this. The following snippet: <p>{1} 2 <span>3</span></p> Complies to: // ... snip
c() {
p = element("p");
t0 = text(t0_value);
t1 = text(" 2 ");
span = element("span");
t2 = text("3");
},
l(nodes) {
p = claim_element(nodes, "P", {});
var p_nodes = children(p);
t0 = claim_text(p_nodes, t0_value);
t1 = claim_text(p_nodes, " 2 ");
span = claim_element(p_nodes, "SPAN", {});
var span_nodes = children(span);
t2 = claim_text(span_nodes, "3");
span_nodes.forEach(detach);
p_nodes.forEach(detach);
},
m(target, anchor) {
insert(target, p, anchor);
append(p, t0);
append(p, t1);
append(p, span);
append(span, t2);
}
// ... snip The rendered html results in the following DOM tree pre hydration:
But Svelte expects:
The first This means the call "falls through" and that a new text node ( Turning those append calls into inserts, or being smarter about text node hydration seems like possible ways to fix this. |
Would turning it into an insert work if there's more text nodes?
Having |
I think this is safe to close now since the change that caused this bug was reversed |
This comment has been minimized.
This comment has been minimized.
Unreverts the hydration optimisation from sveltejs#6204 and fixes the `claim_text` issue as described in sveltejs#6279 (comment)
Describe the bug
On hydration, nodes containing {braced expressions} have their children rendered out of order.
Note that it’s reproducible with 3.38.1.
To Reproduce
The quickest way, probably: https://github.com/intrikate/svelte-hydration-order-issue.
Otherwise, putting an expression and a
span
under a common parent seems to reliably trigger this behaviour. Something like<p>{1} 2 <span>3</span></p>
will hydrate into ‘13 2 ’.Expected behavior
The order of nodes should be preserved in hydration.
Information about your Svelte project:
envinfo
System: OS: macOS 11.2.3 CPU: (4) x64 Intel(R) Core(TM) i5-4288U CPU @ 2.60GHz Memory: 64.55 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.16.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.11 - /usr/local/bin/npm Browsers: Chrome: 90.0.4430.93 Firefox Developer Edition: 89.0 Safari: 14.0.3 npmPackages: svelte: ^3.38.1 => 3.38.1Severity
High.
Additional context
Like #6274, this behaviour is not present in 3.37.0, but, sadly, remains in 3.38.1.
The text was updated successfully, but these errors were encountered: