From ace642f2eb035957c4d0383a30794fce3b836d0b Mon Sep 17 00:00:00 2001 From: Will Chen Date: Thu, 5 Dec 2024 21:21:00 -0800 Subject: [PATCH] Experiment: skip changes if component proto doesn't change --- .../src/component_renderer/component_renderer.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mesop/web/src/component_renderer/component_renderer.ts b/mesop/web/src/component_renderer/component_renderer.ts index 137dfdcd..b1239810 100644 --- a/mesop/web/src/component_renderer/component_renderer.ts +++ b/mesop/web/src/component_renderer/component_renderer.ts @@ -1,10 +1,12 @@ import { ApplicationRef, + ChangeDetectionStrategy, Component, ComponentRef, ElementRef, HostListener, Input, + SimpleChanges, TemplateRef, ViewChild, ViewContainerRef, @@ -59,6 +61,7 @@ const WEB_COMPONENT_PREFIX = ''; MatDividerModule, MatTooltipModule, ], + changeDetection: ChangeDetectionStrategy.OnPush, }) export class ComponentRenderer { @ViewChild('childrenTemplate', {static: true}) @@ -69,7 +72,7 @@ export class ComponentRenderer { @ViewChild('editorOverlay') editorOverlay!: TemplateRef; - @Input() component!: ComponentProto; + @Input('component') component!: ComponentProto; private _boxType: BoxType | undefined; private _componentRef!: ComponentRef; isEditorMode: boolean; @@ -159,7 +162,14 @@ export class ComponentRenderer { } } - ngOnChanges() { + ngOnChanges(changes: SimpleChanges) { + // Note: this isn't a safe check necessarily. + if ( + changes['component'].previousValue?.toString() === + changes['component'].currentValue?.toString() + ) { + return; + } if (this.customElement) { // Update the custom element properties and events this.updateCustomElement(this.customElement);