Skip to content

Commit 0b12680

Browse files
authored
perf(ssr): remove filterProperties (#5101)
1 parent b2468c9 commit 0b12680

File tree

4 files changed

+34
-47
lines changed

4 files changed

+34
-47
lines changed

packages/@lwc/ssr-compiler/src/compile-js/generate-markup.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,14 @@ const bGenerateMarkup = esTemplate`
3131
tagName = tagName ?? ${/*component tag name*/ is.literal};
3232
attrs = attrs ?? Object.create(null);
3333
props = props ?? Object.create(null);
34-
props = __filterProperties(
35-
props,
36-
publicFields,
37-
privateFields,
38-
);
3934
const instance = new ${/* Component class */ is.identifier}({
4035
tagName: tagName.toUpperCase(),
4136
});
4237
4338
__establishContextfulRelationship(contextfulParent, instance);
4439
${/*connect wire*/ is.statement}
4540
46-
instance[__SYMBOL__SET_INTERNALS](props, attrs);
41+
instance[__SYMBOL__SET_INTERNALS](props, attrs, publicFields, privateFields);
4742
instance.isConnected = true;
4843
if (instance.connectedCallback) {
4944
__mutationTracker.enable(instance);
@@ -128,7 +123,6 @@ export function addGenerateMarkupFunction(
128123
program.body.unshift(
129124
bImportDeclaration({
130125
fallbackTmpl: '__fallbackTmpl',
131-
filterProperties: '__filterProperties',
132126
hasScopedStaticStylesheets: undefined,
133127
mutationTracker: '__mutationTracker',
134128
renderAttrs: '__renderAttrs',

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export {
2020
SYMBOL__SET_INTERNALS,
2121
} from './lightning-element';
2222
export { mutationTracker } from './mutation-tracker';
23-
export { filterProperties } from './reflection';
2423
export {
2524
fallbackTmpl,
2625
fallbackTmplNoYield,

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@
1313
// and be located before import statements.
1414
// /// <reference lib="dom" />
1515

16-
import { assign, defineProperties, hasOwnProperty, StringToLowerCase, toString } from '@lwc/shared';
16+
import {
17+
assign,
18+
defineProperties,
19+
hasOwnProperty,
20+
htmlPropertyToAttribute,
21+
isAriaAttribute,
22+
keys,
23+
REFLECTIVE_GLOBAL_PROPERTY_SET,
24+
StringToLowerCase,
25+
toString,
26+
} from '@lwc/shared';
1727

1828
import { ClassList } from './class-list';
1929
import { mutationTracker } from './mutation-tracker';
@@ -64,10 +74,29 @@ export class LightningElement implements PropsAvailableAtConstruction {
6474
assign(this, propsAvailableAtConstruction);
6575
}
6676

67-
[SYMBOL__SET_INTERNALS](props: Properties, attrs: Attributes) {
77+
[SYMBOL__SET_INTERNALS](
78+
props: Properties,
79+
attrs: Attributes,
80+
publicFields: Set<string>,
81+
privateFields: Set<string>
82+
) {
6883
this.#props = props;
6984
this.#attrs = attrs;
70-
assign(this, props);
85+
86+
// Avoid setting the following types of properties that should not be set:
87+
// - Properties that are not public.
88+
// - Properties that are not global.
89+
// - Properties that are global but are internally overridden.
90+
for (const propName of keys(props)) {
91+
const attrName = htmlPropertyToAttribute(propName);
92+
if (
93+
publicFields.has(propName) ||
94+
((REFLECTIVE_GLOBAL_PROPERTY_SET.has(propName) || isAriaAttribute(attrName)) &&
95+
!privateFields.has(propName))
96+
) {
97+
(this as any)[propName] = props[propName];
98+
}
99+
}
71100
}
72101

73102
get className() {

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,10 @@
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
66
*/
77

8-
import {
9-
AriaAttrNameToPropNameMap,
10-
create,
11-
entries,
12-
htmlPropertyToAttribute,
13-
isAriaAttribute,
14-
isNull,
15-
keys,
16-
REFLECTIVE_GLOBAL_PROPERTY_SET,
17-
toString,
18-
} from '@lwc/shared';
8+
import { AriaAttrNameToPropNameMap, entries, isNull, toString } from '@lwc/shared';
199

2010
import type { LightningElement } from './lightning-element';
2111

22-
/**
23-
* Filters out the following types of properties that should not be set.
24-
* - Properties that are not public.
25-
* - Properties that are not global.
26-
* - Properties that are global but are internally overridden.
27-
*/
28-
export function filterProperties(
29-
props: Record<string, unknown>,
30-
publicFields: Set<string>,
31-
privateFields: Set<string>
32-
): Record<string, unknown> {
33-
const propsToAssign = create(null);
34-
for (const propName of keys(props)) {
35-
const attrName = htmlPropertyToAttribute(propName);
36-
if (
37-
publicFields.has(propName) ||
38-
((REFLECTIVE_GLOBAL_PROPERTY_SET.has(propName) || isAriaAttribute(attrName)) &&
39-
!privateFields.has(propName))
40-
) {
41-
propsToAssign[propName] = props[propName];
42-
}
43-
}
44-
return propsToAssign;
45-
}
46-
4712
/**
4813
* Descriptor for IDL attribute reflections that merely reflect the string, e.g. `title`.
4914
*/

0 commit comments

Comments
 (0)