From f59bf85bcfc81b417ba8e410e80c2fd1f0ec22fd Mon Sep 17 00:00:00 2001 From: Kelvin Soh Date: Fri, 20 Oct 2023 01:38:23 +0800 Subject: [PATCH 1/4] 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 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..703ca85bc6cd --- /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 000000000000..bd633c259488 --- /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 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 From b4c16950b06a6a2b9f83236fa5a7a7115c7964a1 Mon Sep 17 00:00:00 2001 From: Kelvin Soh Date: Fri, 20 Oct 2023 02:02:16 +0800 Subject: [PATCH 2/4] fix linting/formatting with prettier --- .../test/hydration/samples/html-tag-hydration/_after.html | 2 +- .../test/hydration/samples/html-tag-hydration/_before.html | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/svelte/test/hydration/samples/html-tag-hydration/_after.html b/packages/svelte/test/hydration/samples/html-tag-hydration/_after.html index 703ca85bc6cd..b85905ec0b99 100644 --- a/packages/svelte/test/hydration/samples/html-tag-hydration/_after.html +++ b/packages/svelte/test/hydration/samples/html-tag-hydration/_after.html @@ -1 +1 @@ -1 2 3 \ No newline at end of file +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 index bd633c259488..820fa84ed462 100644 --- a/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html +++ b/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html @@ -1 +1,3 @@ - 1 2 3 \ No newline at end of file + 1 +2 +3 From 778ef8d68c17cc7626b90aac75d4414b1ed14dcc Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:38:26 +0100 Subject: [PATCH 3/4] Update packages/svelte/test/hydration/samples/html-tag-hydration/_before.html --- .../test/hydration/samples/html-tag-hydration/_before.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html b/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html index 820fa84ed462..a467ac653a21 100644 --- a/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html +++ b/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html @@ -1,3 +1,3 @@ - 1 +1 2 3 From 23688dac83ca441ace2ad69a587f700111c64c4b Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:39:36 +0100 Subject: [PATCH 4/4] Update packages/svelte/test/hydration/samples/html-tag-hydration/_before.html --- .../test/hydration/samples/html-tag-hydration/_before.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html b/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html index a467ac653a21..820fa84ed462 100644 --- a/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html +++ b/packages/svelte/test/hydration/samples/html-tag-hydration/_before.html @@ -1,3 +1,3 @@ -1 + 1 2 3