diff --git a/.changeset/spicy-shrimps-divide.md b/.changeset/spicy-shrimps-divide.md new file mode 100644 index 000000000000..21349a38f0b1 --- /dev/null +++ b/.changeset/spicy-shrimps-divide.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: more robust hydration of html tag diff --git a/packages/svelte/src/runtime/internal/dom.js b/packages/svelte/src/runtime/internal/dom.js index 50e943a13071..01e47ba4c3b9 100644 --- a/packages/svelte/src/runtime/internal/dom.js +++ b/packages/svelte/src/runtime/internal/dom.js @@ -807,6 +807,9 @@ export function claim_html_tag(nodes, is_svg) { detach(html_tag_nodes[0]); detach(html_tag_nodes[html_tag_nodes.length - 1]); const claimed_nodes = html_tag_nodes.slice(1, html_tag_nodes.length - 1); + if (claimed_nodes.length === 0) { + return new HtmlTagHydration(is_svg); + } for (const n of claimed_nodes) { n.claim_order = nodes.claim_info.total_claimed; nodes.claim_info.total_claimed += 1; diff --git a/packages/svelte/test/hydration/samples/html-tag-hydration/_after.html b/packages/svelte/test/hydration/samples/html-tag-hydration/_after.html new file mode 100644 index 000000000000..b85905ec0b99 --- /dev/null +++ b/packages/svelte/test/hydration/samples/html-tag-hydration/_after.html @@ -0,0 +1 @@ +1 2 3 diff --git a/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html b/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html new file mode 100644 index 000000000000..820fa84ed462 --- /dev/null +++ b/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html @@ -0,0 +1,3 @@ + 1 +2 +3 diff --git a/packages/svelte/test/hydration/samples/html-tag-hydration/main.svelte b/packages/svelte/test/hydration/samples/html-tag-hydration/main.svelte new file mode 100644 index 000000000000..f90ddea30596 --- /dev/null +++ b/packages/svelte/test/hydration/samples/html-tag-hydration/main.svelte @@ -0,0 +1,5 @@ + + +{a} {@html b} {c} \ No newline at end of file