Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-svelte-element-hydration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: handle svelte:element hydration within raw text elements
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
assign_nodes(element, element);

if (render_fn) {
/** @type {Comment | null} */
var comment = null;

if (hydrating && is_raw_text_element(next_tag)) {
// prevent hydration glitches
element.append(document.createComment(''));
comment = document.createComment('');
element.append(comment);
}

// If hydrating, use the existing ssr comment as the anchor so that the
Expand All @@ -115,6 +119,10 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
// and the DOM will be silently discarded
render_fn(element, child_anchor);

if (comment !== null) {
comment.remove();
}

set_animation_effect_override(null);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
hydrate: true,
html: '<div><style>body { color: red; }</style></div>'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
let { tag = 'style' } = $props();
const css = 'body { color: red; }';
</script>

<div>
<svelte:element this={tag}>{css}</svelte:element>
</div>