Skip to content

Commit af02914

Browse files
crisbetommalerba
authored andcommitted
fix(core): cache ComponentRef inputs and outputs (#60156)
The set of inputs and outputs of a component is static, but the getter for the `inputs` and `outputs` property was re-computing them every time which the user might not expect. These changes add a couple of lines to cache them instead. PR Close #60156
1 parent 7ab0a8d commit af02914

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/core/src/render3/component_ref.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,29 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
186186
override componentType: Type<any>;
187187
override ngContentSelectors: string[];
188188
isBoundToModule: boolean;
189+
private cachedInputs:
190+
| {
191+
propName: string;
192+
templateName: string;
193+
isSignal: boolean;
194+
transform?: (value: any) => any;
195+
}[]
196+
| null = null;
197+
private cachedOutputs: {propName: string; templateName: string}[] | null = null;
189198

190199
override get inputs(): {
191200
propName: string;
192201
templateName: string;
193202
isSignal: boolean;
194203
transform?: (value: any) => any;
195204
}[] {
196-
return toInputRefArray(this.componentDef.inputs);
205+
this.cachedInputs ??= toInputRefArray(this.componentDef.inputs);
206+
return this.cachedInputs;
197207
}
198208

199209
override get outputs(): {propName: string; templateName: string}[] {
200-
return toOutputRefArray(this.componentDef.outputs);
210+
this.cachedOutputs ??= toOutputRefArray(this.componentDef.outputs);
211+
return this.cachedOutputs;
201212
}
202213

203214
/**

0 commit comments

Comments
 (0)