feat(runtime-browser): add support for <svelte:element this="contents"> to render children without wrapper

- Added handling in element block to treat "contents" as no-wrapper rendering
- Added runtime-browser test for this behavior
pull/16392/head
Bohdan Dukhevych 2 months ago
parent e01bd97bef
commit 32a29d9ee9

@ -0,0 +1,5 @@
---
'svelte': minor
---
Add support for `<svelte:element this="contents">` to render children without wrapper element

@ -96,7 +96,15 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
}
}
if (next_tag && next_tag !== current_tag) {
if (next_tag === 'contents') {
// Don't mount anything; just execute render_fn directly with anchor
effect = branch(() => {
if (render_fn) {
render_fn(anchor.parentNode, anchor);
}
/** @type {Effect} */ (active_effect).nodes_end = anchor;
});
} else if (next_tag && next_tag !== current_tag) {
effect = branch(() => {
element = hydrating
? /** @type {Element} */ (element)

@ -0,0 +1,12 @@
import { test } from '../../assert';
export default test({
mode: ['client'],
async test({ assert, window }) {
await new Promise((r) => setTimeout(r, 1000));
assert.htmlEqual(
window.document.body.innerHTML,
`<main><strong>Hello</strong></main>`
);
}
});

@ -0,0 +1,7 @@
<script>
let tag = 'contents';
</script>
<svelte:element this={tag}>
<strong>Hello</strong>
</svelte:element>
Loading…
Cancel
Save