From 10c2e746b2d2de8ce550b3c15b18e98822b93b56 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sun, 12 Jun 2022 17:56:25 -0700 Subject: [PATCH] Don't re-render the whole card for conditionState. --- src/card.ts | 15 ++++++++++++++- src/components/elements.ts | 4 ++-- src/components/live.ts | 6 +++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/card.ts b/src/card.ts index 9096c713..21b442d2 100644 --- a/src/card.ts +++ b/src/card.ts @@ -28,6 +28,7 @@ import './components/gallery.js'; import './components/image.js'; import { FrigateCardImage } from './components/image.js'; import './components/live.js'; +import { FrigateCardLive } from './components/live.js'; import './components/menu.js'; import { FrigateCardMenu, FRIGATE_BUTTON_MENU_ICON } from './components/menu.js'; import './components/message.js'; @@ -164,12 +165,12 @@ export class FrigateCard extends LitElement { @property({ attribute: false }) protected _view?: View; - @state() protected _conditionState?: ConditionState; protected _refMenu: Ref = createRef(); protected _refElements: Ref = createRef(); protected _refImage: Ref = createRef(); + protected _refLive: Ref = createRef(); // user interaction timer ("screensaver" functionality, return to default // view after user interaction). @@ -273,6 +274,17 @@ export class FrigateCard extends LitElement { state: this._hass?.states, }; + // Update the components that need the new condition state. Passed directly + // to them to avoid the performance hit of a entire card re-render (esp. + // when using card-mod). + // https://github.com/dermotduffy/frigate-hass-card/issues/678 + if (this._refLive.value) { + this._refLive.value.conditionState = this._conditionState; + } + if (this._refElements.value) { + this._refElements.value.conditionState = this._conditionState; + } + const overriddenConfig = getOverriddenConfig( this._config, this._config.overrides, @@ -1813,6 +1825,7 @@ export class FrigateCard extends LitElement { this._getConfig().live.preload || (!this._message && this._view.is('live')) ? html`