Update the elements root when the config changes.

This commit is contained in:
Dermot Duffy
2022-05-09 16:34:06 -07:00
parent 7c9cfdaaa5
commit 47e2f47b58
+13 -6
View File
@@ -1,4 +1,11 @@
import { LitElement, TemplateResult, html, CSSResultGroup, unsafeCSS } from 'lit'; import {
LitElement,
TemplateResult,
html,
CSSResultGroup,
unsafeCSS,
PropertyValues,
} from 'lit';
import { HomeAssistant } from 'custom-card-helpers'; import { HomeAssistant } from 'custom-card-helpers';
import { customElement, property } from 'lit/decorators.js'; import { customElement, property } from 'lit/decorators.js';
@@ -110,12 +117,12 @@ export class FrigateCardElementsCore extends LitElement {
/** /**
* Create the root as necessary prior to rendering. * Create the root as necessary prior to rendering.
*/ */
protected willUpdate(): void { protected willUpdate(changedProps: PropertyValues): void {
try { try {
// The root is only created once, to avoid the elements being continually // The root is only created once per elements configuration change, to
// re-created & destroyed (for some elements, e.g. image, this would // avoid the elements being continually re-created & destroyed (for some
// otherwise cause serious flickering). // elements, e.g. image, recreation causes a flicker).
if (!this._root) { if (this.elements && (!this._root || changedProps.has('elements'))) {
this._root = this._createRoot(); this._root = this._createRoot();
} }
} catch (e) { } catch (e) {