feat: better `<svelte:element>` SSR output (#12339)

pull/12342/head
Rich Harris 2 months ago committed by GitHub
parent a59bc99782
commit bbf489504d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
feat: better `<svelte:element>` SSR output

@ -1338,12 +1338,18 @@ const template_visitors = {
context.visit(node.fragment, state)
);
const body = b.stmt(
b.call('$.element', b.id('$$payload'), tag, b.thunk(attributes), b.thunk(children))
context.state.template.push(
b.stmt(
b.call(
'$.element',
b.id('$$payload'),
tag,
attributes.body.length > 0 && b.thunk(attributes),
children.body.length > 0 && b.thunk(children)
)
)
);
context.state.template.push(b.if(tag, body), block_anchor);
if (context.state.options.dev) {
context.state.template.push(b.stmt(b.call('$.pop_element')));
}

@ -72,7 +72,8 @@ export function assign_payload(p1, p2) {
* @param {() => void} children_fn
* @returns {void}
*/
export function element(payload, tag, attributes_fn, children_fn) {
export function element(payload, tag, attributes_fn = noop, children_fn = noop) {
if (tag) {
payload.out += `<${tag} `;
attributes_fn();
payload.out += `>`;
@ -86,6 +87,9 @@ export function element(payload, tag, attributes_fn, children_fn) {
}
}
payload.out += '<!---->';
}
/**
* Array of `onDestroy` callbacks that should be called at the end of the server render function
* @type {Function[]}

@ -3,6 +3,5 @@ import * as $ from "svelte/internal/server";
export default function Svelte_element($$payload, $$props) {
let { tag = 'hr' } = $$props;
if (tag) $.element($$payload, tag, () => {}, () => {});
$$payload.out += `<!---->`;
$.element($$payload, tag);
}
Loading…
Cancel
Save