From f59bf85bcfc81b417ba8e410e80c2fd1f0ec22fd Mon Sep 17 00:00:00 2001 From: Kelvin Soh Date: Fri, 20 Oct 2023 01:38:23 +0800 Subject: [PATCH] fix html tag hydration --- .changeset/spicy-shrimps-divide.md | 5 +++++ packages/svelte/src/runtime/internal/dom.js | 3 +++ .../test/hydration/samples/html-tag-hydration/_after.html | 1 + .../test/hydration/samples/html-tag-hydration/_before.html | 1 + .../test/hydration/samples/html-tag-hydration/main.svelte | 5 +++++ 5 files changed, 15 insertions(+) create mode 100644 .changeset/spicy-shrimps-divide.md create mode 100644 packages/svelte/test/hydration/samples/html-tag-hydration/_after.html create mode 100644 packages/svelte/test/hydration/samples/html-tag-hydration/_before.html create mode 100644 packages/svelte/test/hydration/samples/html-tag-hydration/main.svelte diff --git a/.changeset/spicy-shrimps-divide.md b/.changeset/spicy-shrimps-divide.md new file mode 100644 index 0000000000..21349a38f0 --- /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 50e943a130..01e47ba4c3 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 0000000000..703ca85bc6 --- /dev/null +++ b/packages/svelte/test/hydration/samples/html-tag-hydration/_after.html @@ -0,0 +1 @@ +1 2 3 \ No newline at end of file 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 0000000000..bd633c2594 --- /dev/null +++ b/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html @@ -0,0 +1 @@ + 1 2 3 \ No newline at end of file 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 0000000000..f90ddea305 --- /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