Skip to content

Commit 47d26b3

Browse files
authored
perf(ssr): avoid proxying entire props object (#5125)
1 parent b02b0b9 commit 47d26b3

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

packages/@lwc/ssr-compiler/src/compile-template/transformers/component/component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { Transformer } from '../../types';
1717

1818
const bYieldFromChildGenerator = esTemplateWithYield`
1919
{
20-
const childProps = __getReadOnlyProxy(${/* child props */ is.objectExpression});
20+
const childProps = ${/* child props */ is.objectExpression};
2121
const childAttrs = ${/* child attrs */ is.objectExpression};
2222
${
2323
/*
@@ -52,7 +52,6 @@ export const Component: Transformer<IrComponent> = function Component(node, cxt)
5252
const importPath = kebabcaseToCamelcase(node.name);
5353
cxt.import({ default: childComponentLocalName }, importPath);
5454
cxt.import({
55-
getReadOnlyProxy: '__getReadOnlyProxy',
5655
SYMBOL__GENERATE_MARKUP: '__SYMBOL__GENERATE_MARKUP',
5756
});
5857
const childTagName = node.name;

packages/@lwc/ssr-compiler/src/compile-template/transformers/component/lwc-component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const bYieldFromDynamicComponentConstructorGenerator = esTemplateWithYield`
2323
if (typeof Ctor !== 'function' || !(Ctor.prototype instanceof LightningElement)) {
2424
throw new Error(\`Invalid constructor: "\${String(Ctor)}" is not a LightningElement constructor.\`)
2525
}
26-
const childProps = __getReadOnlyProxy(${/* child props */ is.objectExpression});
26+
const childProps = ${/* child props */ is.objectExpression};
2727
const childAttrs = ${/* child attrs */ is.objectExpression};
2828
${
2929
/*
@@ -57,7 +57,6 @@ export const LwcComponent: Transformer<IrLwcComponent> = function LwcComponent(n
5757
const lwcIs = directives.find((directive) => directive.name === 'Is');
5858
if (!isUndefined(lwcIs)) {
5959
cxt.import({
60-
getReadOnlyProxy: '__getReadOnlyProxy',
6160
LightningElement: undefined,
6261
SYMBOL__GENERATE_MARKUP: '__SYMBOL__GENERATE_MARKUP',
6362
});

packages/@lwc/ssr-runtime/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export * from './stubs';
1111
export { htmlEscape, setHooks, sanitizeHtmlContent, normalizeClass } from '@lwc/shared';
1212

1313
export { ClassList } from './class-list';
14-
export { getReadOnlyProxy } from './get-read-only-proxy';
1514
export {
1615
LightningElement,
1716
LightningElementConstructor,

packages/@lwc/ssr-runtime/src/lightning-element.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import { ClassList } from './class-list';
2929
import { mutationTracker } from './mutation-tracker';
3030
import { descriptors as reflectionDescriptors } from './reflection';
31+
import { getReadOnlyProxy } from './get-read-only-proxy';
3132
import type { Attributes, Properties } from './types';
3233
import type { Stylesheets } from '@lwc/shared';
3334

@@ -94,7 +95,9 @@ export class LightningElement implements PropsAvailableAtConstruction {
9495
((REFLECTIVE_GLOBAL_PROPERTY_SET.has(propName) || isAriaAttribute(attrName)) &&
9596
!privateFields.has(propName))
9697
) {
97-
(this as any)[propName] = props[propName];
98+
// For props passed from parents to children, they are intended to be read-only
99+
// to avoid a child mutating its parent's state
100+
(this as any)[propName] = getReadOnlyProxy(props[propName]);
98101
}
99102
}
100103
}

0 commit comments

Comments
 (0)