fix: handle falsy dynamic components in SSR (#17542)

* fix: handle falsy dynamic components in SSR

Closes #17408

Adds a dynamic check for the component in the SSR.

Changes:
- Modified server-side component renderer to use b.maybe_call for dynamic components
- Added SSR test case for falsy component values

* fix types

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/17546/head
ai-man-codes 2 days ago committed by GitHub
parent c3fcc15cfa
commit efcb7353bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: handle false dynamic components in SSR

@ -295,22 +295,18 @@ export function build_inline_component(node, expression, context) {
b.array(props_and_spreads.map((p) => (Array.isArray(p) ? b.object(p) : p)))
);
const dynamic =
node.type === 'SvelteComponent' || (node.type === 'Component' && node.metadata.dynamic);
/** @type {Statement} */
let statement = b.stmt(
(node.type === 'SvelteComponent' ? b.maybe_call : b.call)(
expression,
b.id('$$renderer'),
props_expression
)
(dynamic ? b.maybe_call : b.call)(expression, b.id('$$renderer'), props_expression)
);
if (snippet_declarations.length > 0) {
statement = b.block([...snippet_declarations, statement]);
}
const dynamic =
node.type === 'SvelteComponent' || (node.type === 'Component' && node.metadata.dynamic);
if (custom_css_props.length > 0) {
statement = b.stmt(
b.call(

@ -0,0 +1,6 @@
<script>
let Component = $state();
</script>
<h1>Test</h1>
<Component />
Loading…
Cancel
Save