From b71888b877c488f1df98bc5f83172a1d33d09482 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Thu, 27 Jun 2024 16:07:22 +0200 Subject: [PATCH] Use hasupdated --- src/panels/lovelace/cards/hui-card.ts | 31 +++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/panels/lovelace/cards/hui-card.ts b/src/panels/lovelace/cards/hui-card.ts index e2cdc1ff209f..ee77c8818ec2 100644 --- a/src/panels/lovelace/cards/hui-card.ts +++ b/src/panels/lovelace/cards/hui-card.ts @@ -124,27 +124,30 @@ export class HuiCard extends ReactiveElement { this._updateVisibility(); } - protected update(changedProps: PropertyValues) { - super.update(changedProps); + protected willUpdate(changedProps: PropertyValues): void { + super.willUpdate(changedProps); if (!this._element) { this.build(); } + } - if (changedProps.has("config")) { - const oldConfig = changedProps.get("config"); - if (this.config && oldConfig && this.config !== oldConfig) { - const typeChanged = this.config.type !== oldConfig.type; - if (typeChanged) { - this._buildElement(this.config); - } else { - this._element?.setConfig(this.config); - fireEvent(this, "card-updated"); - } - } - } + protected update(changedProps: PropertyValues) { + super.update(changedProps); if (this._element) { + if (changedProps.has("config") && this.hasUpdated) { + const oldConfig = changedProps.get("config"); + if (this.config !== oldConfig && this.config) { + const typeChanged = this.config?.type !== oldConfig?.type; + if (typeChanged) { + this._buildElement(this.config); + } else { + this._element?.setConfig(this.config); + fireEvent(this, "card-updated"); + } + } + } if (changedProps.has("hass")) { try { if (this.hass) {