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 https://github.com/sveltejs/kit/issues/10245
pull/8898/head
Simon H 2 years ago committed by GitHub
parent b9328a5077
commit d2ff04f9fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: use non-destructive hydration for all `@html` tags

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

@ -1,9 +1,7 @@
export default {
html: `
<svg>
<foreignObject>
<circle cx="25" cy="30" r="24" fill="#FFD166"></circle>
</foreignObject>
<foreignObject><!-- HTML_TAG_START --><circle cx="25" cy="30" r="24" fill="#FFD166"></circle><!-- HTML_TAG_END --></foreignObject>
</svg>
`,
test({ assert, target, component }) {

@ -1,7 +1,7 @@
<script>
export let width = 100
export let height = 60
$: circle = `<circle cx="${width/4}" cy="${height/2}" r="24" fill="#FFD166"/>`
export let width = 100;
export let height = 60;
$: circle = `<circle cx="${width / 4}" cy="${height / 2}" r="24" fill="#FFD166"></circle>`;
</script>
<svg>

Loading…
Cancel
Save