Skip to content

Commit d2ff04f

Browse files
authored
fix: use non-destructive hydration for all @html tags (#8880)
html tags that could be optimized to use innerHTML in mount ignored any hydration code, which leads to everything getting unmounted and mounted again. This takes the non-optimized path for hydration, too. fixes sveltejs/kit#10245
1 parent b9328a5 commit d2ff04f

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

.changeset/pretty-trees-prove.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: use non-destructive hydration for all `@html` tags

packages/svelte/src/compiler/compile/render_dom/wrappers/RawMustacheTag.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default class RawMustacheTagWrapper extends Tag {
2626
render(block, parent_node, _parent_nodes) {
2727
const in_head = is_head(parent_node);
2828
const can_use_innerhtml = !in_head && parent_node && !this.prev && !this.next;
29-
if (can_use_innerhtml) {
29+
if (can_use_innerhtml && !this.renderer.options.hydratable) {
3030
/** @param {import('estree').Node} content */
3131
const insert = (content) => b`${parent_node}.innerHTML = ${content};`[0];
3232
const { init } = this.rename_this_method(block, (content) => insert(content));

packages/svelte/test/runtime/samples/svg-html-tag3/_config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
export default {
22
html: `
33
<svg>
4-
<foreignObject>
5-
<circle cx="25" cy="30" r="24" fill="#FFD166"></circle>
6-
</foreignObject>
4+
<foreignObject><!-- HTML_TAG_START --><circle cx="25" cy="30" r="24" fill="#FFD166"></circle><!-- HTML_TAG_END --></foreignObject>
75
</svg>
86
`,
97
test({ assert, target, component }) {

packages/svelte/test/runtime/samples/svg-html-tag3/main.svelte

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
2-
export let width = 100
3-
export let height = 60
4-
$: circle = `<circle cx="${width/4}" cy="${height/2}" r="24" fill="#FFD166"/>`
2+
export let width = 100;
3+
export let height = 60;
4+
$: circle = `<circle cx="${width / 4}" cy="${height / 2}" r="24" fill="#FFD166"></circle>`;
55
</script>
66

77
<svg>

0 commit comments

Comments
 (0)