diff --git a/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js b/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js index bf6041abcd53..4a68d1e0c692 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/transform-server.js @@ -2355,7 +2355,9 @@ export function server_component(analysis, options) { .../** @type {import('estree').Statement[]} */ (template.body) ]); - if (analysis.needs_context || options.dev) { + let should_inject_context = analysis.needs_context || options.dev; + + if (should_inject_context) { component_block.body.unshift(b.stmt(b.call('$.push', ...push_args))); component_block.body.push(b.stmt(b.call('$.pop'))); } @@ -2391,9 +2393,18 @@ export function server_component(analysis, options) { const body = [...state.hoisted, ...module.body]; + let should_inject_props = + should_inject_context || + props.length > 0 || + analysis.needs_props || + analysis.uses_props || + analysis.uses_rest_props || + analysis.uses_slots || + analysis.slot_names.size > 0; + const component_function = b.function_declaration( b.id(analysis.name), - [b.id('$$payload'), b.id('$$props')], + should_inject_props ? [b.id('$$payload'), b.id('$$props')] : [b.id('$$payload')], component_block ); if (options.legacy.componentApi) { diff --git a/packages/svelte/tests/snapshot/samples/bind-component-snippet/_expected/server/index.svelte.js b/packages/svelte/tests/snapshot/samples/bind-component-snippet/_expected/server/index.svelte.js index dc0724ea9a79..5c9a37cfdbf2 100644 --- a/packages/svelte/tests/snapshot/samples/bind-component-snippet/_expected/server/index.svelte.js +++ b/packages/svelte/tests/snapshot/samples/bind-component-snippet/_expected/server/index.svelte.js @@ -1,7 +1,7 @@ import * as $ from "svelte/internal/server"; import TextInput from './Child.svelte'; -export default function Bind_component_snippet($$payload, $$props) { +export default function Bind_component_snippet($$payload) { let value = ''; const _snippet = snippet; diff --git a/packages/svelte/tests/snapshot/samples/bind-this/_expected/server/index.svelte.js b/packages/svelte/tests/snapshot/samples/bind-this/_expected/server/index.svelte.js index dfd5203a0b4a..98c5fd7ae747 100644 --- a/packages/svelte/tests/snapshot/samples/bind-this/_expected/server/index.svelte.js +++ b/packages/svelte/tests/snapshot/samples/bind-this/_expected/server/index.svelte.js @@ -1,6 +1,6 @@ import * as $ from "svelte/internal/server"; -export default function Bind_this($$payload, $$props) { +export default function Bind_this($$payload) { $$payload.out += ``; Foo($$payload, {}); $$payload.out += ``; diff --git a/packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/_expected/server/main.svelte.js b/packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/_expected/server/main.svelte.js index 016165581111..c04217884414 100644 --- a/packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/_expected/server/main.svelte.js +++ b/packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/_expected/server/main.svelte.js @@ -1,6 +1,6 @@ import * as $ from "svelte/internal/server"; -export default function Main($$payload, $$props) { +export default function Main($$payload) { // needs to be a snapshot test because jsdom does auto-correct the attribute casing let x = 'test'; let y = () => 'test'; diff --git a/packages/svelte/tests/snapshot/samples/each-string-template/_expected/server/index.svelte.js b/packages/svelte/tests/snapshot/samples/each-string-template/_expected/server/index.svelte.js index 2f6f50ef2db7..fb143a56c9dd 100644 --- a/packages/svelte/tests/snapshot/samples/each-string-template/_expected/server/index.svelte.js +++ b/packages/svelte/tests/snapshot/samples/each-string-template/_expected/server/index.svelte.js @@ -1,6 +1,6 @@ import * as $ from "svelte/internal/server"; -export default function Each_string_template($$payload, $$props) { +export default function Each_string_template($$payload) { const each_array = $.ensure_array_like(['foo', 'bar', 'baz']); $$payload.out += ``; diff --git a/packages/svelte/tests/snapshot/samples/function-prop-no-getter/_expected/server/index.svelte.js b/packages/svelte/tests/snapshot/samples/function-prop-no-getter/_expected/server/index.svelte.js index 6a5afe0d613e..974be7fcf6c2 100644 --- a/packages/svelte/tests/snapshot/samples/function-prop-no-getter/_expected/server/index.svelte.js +++ b/packages/svelte/tests/snapshot/samples/function-prop-no-getter/_expected/server/index.svelte.js @@ -1,6 +1,6 @@ import * as $ from "svelte/internal/server"; -export default function Function_prop_no_getter($$payload, $$props) { +export default function Function_prop_no_getter($$payload) { let count = 0; function onmouseup() { diff --git a/packages/svelte/tests/snapshot/samples/hello-world/_expected/server/index.svelte.js b/packages/svelte/tests/snapshot/samples/hello-world/_expected/server/index.svelte.js index a3d808796cbb..a313799dfd34 100644 --- a/packages/svelte/tests/snapshot/samples/hello-world/_expected/server/index.svelte.js +++ b/packages/svelte/tests/snapshot/samples/hello-world/_expected/server/index.svelte.js @@ -1,5 +1,5 @@ import * as $ from "svelte/internal/server"; -export default function Hello_world($$payload, $$props) { +export default function Hello_world($$payload) { $$payload.out += `