Skip to content

Commit ac5a803

Browse files
committed
same but for $$props
1 parent 8160831 commit ac5a803

File tree

9 files changed

+21
-10
lines changed

9 files changed

+21
-10
lines changed

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,7 +2355,9 @@ export function server_component(analysis, options) {
23552355
.../** @type {import('estree').Statement[]} */ (template.body)
23562356
]);
23572357

2358-
if (analysis.needs_context || options.dev) {
2358+
let should_inject_context = analysis.needs_context || options.dev;
2359+
2360+
if (should_inject_context) {
23592361
component_block.body.unshift(b.stmt(b.call('$.push', ...push_args)));
23602362
component_block.body.push(b.stmt(b.call('$.pop')));
23612363
}
@@ -2391,9 +2393,18 @@ export function server_component(analysis, options) {
23912393

23922394
const body = [...state.hoisted, ...module.body];
23932395

2396+
let should_inject_props =
2397+
should_inject_context ||
2398+
props.length > 0 ||
2399+
analysis.needs_props ||
2400+
analysis.uses_props ||
2401+
analysis.uses_rest_props ||
2402+
analysis.uses_slots ||
2403+
analysis.slot_names.size > 0;
2404+
23942405
const component_function = b.function_declaration(
23952406
b.id(analysis.name),
2396-
[b.id('$$payload'), b.id('$$props')],
2407+
should_inject_props ? [b.id('$$payload'), b.id('$$props')] : [b.id('$$payload')],
23972408
component_block
23982409
);
23992410
if (options.legacy.componentApi) {

packages/svelte/tests/snapshot/samples/bind-component-snippet/_expected/server/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as $ from "svelte/internal/server";
22
import TextInput from './Child.svelte';
33

4-
export default function Bind_component_snippet($$payload, $$props) {
4+
export default function Bind_component_snippet($$payload) {
55
let value = '';
66
const _snippet = snippet;
77

packages/svelte/tests/snapshot/samples/bind-this/_expected/server/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as $ from "svelte/internal/server";
22

3-
export default function Bind_this($$payload, $$props) {
3+
export default function Bind_this($$payload) {
44
$$payload.out += `<!--[-->`;
55
Foo($$payload, {});
66
$$payload.out += `<!--]-->`;

packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/_expected/server/main.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as $ from "svelte/internal/server";
22

3-
export default function Main($$payload, $$props) {
3+
export default function Main($$payload) {
44
// needs to be a snapshot test because jsdom does auto-correct the attribute casing
55
let x = 'test';
66
let y = () => 'test';

packages/svelte/tests/snapshot/samples/each-string-template/_expected/server/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as $ from "svelte/internal/server";
22

3-
export default function Each_string_template($$payload, $$props) {
3+
export default function Each_string_template($$payload) {
44
const each_array = $.ensure_array_like(['foo', 'bar', 'baz']);
55

66
$$payload.out += `<!--[-->`;

packages/svelte/tests/snapshot/samples/function-prop-no-getter/_expected/server/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as $ from "svelte/internal/server";
22

3-
export default function Function_prop_no_getter($$payload, $$props) {
3+
export default function Function_prop_no_getter($$payload) {
44
let count = 0;
55

66
function onmouseup() {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as $ from "svelte/internal/server";
22

3-
export default function Hello_world($$payload, $$props) {
3+
export default function Hello_world($$payload) {
44
$$payload.out += `<h1>hello world</h1>`;
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as $ from "svelte/internal/server";
22

3-
export default function Hmr($$payload, $$props) {
3+
export default function Hmr($$payload) {
44
$$payload.out += `<h1>hello world</h1>`;
55
}

packages/svelte/tests/snapshot/samples/state-proxy-literal/_expected/server/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as $ from "svelte/internal/server";
22

3-
export default function State_proxy_literal($$payload, $$props) {
3+
export default function State_proxy_literal($$payload) {
44
let str = '';
55
let tpl = ``;
66

0 commit comments

Comments
 (0)