Fix race in lovelace (#19609)

This commit is contained in:
Bram Kragten 2024-02-01 17:56:46 +01:00 committed by GitHub
parent 69f2566526
commit 28a0d216f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -73,6 +73,8 @@ export class LovelacePanel extends LitElement {
private _unsubUpdates?: Promise<UnsubscribeFunc>; private _unsubUpdates?: Promise<UnsubscribeFunc>;
private _loading = false;
public connectedCallback(): void { public connectedCallback(): void {
super.connectedCallback(); super.connectedCallback();
if ( if (
@ -162,7 +164,7 @@ export class LovelacePanel extends LitElement {
protected willUpdate(changedProps: PropertyValues) { protected willUpdate(changedProps: PropertyValues) {
super.willUpdate(changedProps); super.willUpdate(changedProps);
if (!this.lovelace && this._panelState !== "error") { if (!this.lovelace && this._panelState !== "error" && !this._loading) {
this._fetchConfig(false); this._fetchConfig(false);
} }
} }
@ -233,6 +235,8 @@ export class LovelacePanel extends LitElement {
} }
private async _fetchConfig(forceDiskRefresh: boolean) { private async _fetchConfig(forceDiskRefresh: boolean) {
this._loading = true;
let conf: LovelaceConfig; let conf: LovelaceConfig;
let rawConf: LovelaceRawConfig | undefined; let rawConf: LovelaceRawConfig | undefined;
let confMode: Lovelace["mode"] = this.panel!.config.mode; let confMode: Lovelace["mode"] = this.panel!.config.mode;
@ -301,6 +305,7 @@ export class LovelacePanel extends LitElement {
rawConf = DEFAULT_CONFIG; rawConf = DEFAULT_CONFIG;
confMode = "generated"; confMode = "generated";
} finally { } finally {
this._loading = false;
// Ignore updates for another 2 seconds. // Ignore updates for another 2 seconds.
if (this.lovelace && this.lovelace.mode === "yaml") { if (this.lovelace && this.lovelace.mode === "yaml") {
setTimeout(() => { setTimeout(() => {