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) { render(block, parent_node, _parent_nodes) {
const in_head = is_head(parent_node); const in_head = is_head(parent_node);
const can_use_innerhtml = !in_head && parent_node && !this.prev && !this.next; 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 */ /** @param {import('estree').Node} content */
const insert = (content) => b`${parent_node}.innerHTML = ${content};`[0]; const insert = (content) => b`${parent_node}.innerHTML = ${content};`[0];
const { init } = this.rename_this_method(block, (content) => insert(content)); const { init } = this.rename_this_method(block, (content) => insert(content));

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

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

Loading…
Cancel
Save