From af02914852cb26106090e07aee155890df1798ff Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Fri, 28 Feb 2025 09:05:37 +0100 Subject: [PATCH] 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 --- packages/core/src/render3/component_ref.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/core/src/render3/component_ref.ts b/packages/core/src/render3/component_ref.ts index 3ac783fad51..b5e60d328da 100644 --- a/packages/core/src/render3/component_ref.ts +++ b/packages/core/src/render3/component_ref.ts @@ -186,6 +186,15 @@ export class ComponentFactory extends AbstractComponentFactory { override componentType: Type; override ngContentSelectors: string[]; isBoundToModule: boolean; + private cachedInputs: + | { + propName: string; + templateName: string; + isSignal: boolean; + transform?: (value: any) => any; + }[] + | null = null; + private cachedOutputs: {propName: string; templateName: string}[] | null = null; override get inputs(): { propName: string; @@ -193,11 +202,13 @@ export class ComponentFactory extends AbstractComponentFactory { isSignal: boolean; transform?: (value: any) => any; }[] { - return toInputRefArray(this.componentDef.inputs); + this.cachedInputs ??= toInputRefArray(this.componentDef.inputs); + return this.cachedInputs; } override get outputs(): {propName: string; templateName: string}[] { - return toOutputRefArray(this.componentDef.outputs); + this.cachedOutputs ??= toOutputRefArray(this.componentDef.outputs); + return this.cachedOutputs; } /**