-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: do not reuse claimed nodes if the html does not match #7469
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
Conversation
c780564 to
09ff6f9
Compare
09ff6f9 to
4a473e3
Compare
|
According to the repl of sveltejs/kit#2977, now it works OK. Should we do like this way? let ssr_html = '';
for (const n of claimed_nodes) {
ssr_html += n.outerHTML || '';
}
let normalized_html = '';
const temp_div = document.createElement('div');
temp_div.innerHTML = html;
for (const n of normalized_html.childNodes) {
normalized_html += n.outerHTML || '';
}
if (ssr_html !== normalized_html) {
for (const n of claimed_nodes) {
detach(n);
}
return new HtmlTagHydration(undefined, is_svg);
} |
|
i hvnt tried, but what was the reason that multiple root nodes causes the one thing i can think of that this approach has potential bug is that, the parent element cannot always be |
|
I realise if there's text nodes, will need to |
|
I have good specific example! If I have this svelte file. <script context="module">
export const hydrate = true;
export const prerender = true;
</script>
<script>
const content = `<div>xxxxxxx</div>
<p>yyyy<b>yyyy</b>yyyy</p>
<p>zzzzzz</p>`;
</script>
<h1>Hello World</h1>
{@html content}
<p id="p">Bye World</p>ssr_html is: <div>xxxxxxx</div>undefined<p>yyyy<b>yyyy</b>yyyy</p>undefined<p>zzzzzz</p>html is: <div>xxxxxxx</div>
<p>yyyy<b>yyyy</b>yyyy</p>
<p>zzzzzz</p>DIfferent points are
Ah yes. But in any way, I think we need to handle this in some way. |
Yeah I also forgot And after adding this, now |
|
oh really, so the extra indent, newline, spaces are captured nicely within |
Yes. I found one more issue which is boolean attr issue. And regarding SVG. And when I check SVG, I realized the below pattern. <script context="module">
export const hydrate = true;
export const prerender = true;
</script>
<script>
const content = `<svg><rect x="0" y="0" width="100" height="60" fill="#ddd" />
<polygon points="50 10, 70 30, 50 50, 30 30" fill="#99f" /></svg>`;
</script>
{@html content}ssr_html is: <svg><rect x="0" y="0" width="100" height="60" fill="#ddd"></rect>
<polygon points="50 10, 70 30, 50 50, 30 30" fill="#99f"></polygon></svg>but html is <svg><rect x="0" y="0" width="100" height="60" fill="#ddd" />
<polygon points="50 10, 70 30, 50 50, 30 30" fill="#99f" /></svg> |
|
What's the status of this? Haven't followed the conversation closely, but it sounds like there's some improvements to be made to this PR? |
|
Closing, as Svelte 5 has a more robust hydration mechanism |
Fixes sveltejs/kit#2977
Before submitting the PR, please make sure you do the following
[feat],[fix],[chore], or[docs].Tests
npm testand lint the project withnpm run lint