mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Fix markdown card crashing the demo (#5962)
This commit is contained in:
parent
389b7def0b
commit
e4607735ff
@ -41,7 +41,7 @@ export class HuiMarkdownCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
@property() private _content = "";
|
@property() private _content = "";
|
||||||
|
|
||||||
@property() private _unsubRenderTemplate?: Promise<UnsubscribeFunc>;
|
@property() private _unsubRenderTemplate?: UnsubscribeFunc;
|
||||||
|
|
||||||
public getCardSize(): number {
|
public getCardSize(): number {
|
||||||
return this._config === undefined
|
return this._config === undefined
|
||||||
@ -121,7 +121,8 @@ export class HuiMarkdownCard extends LitElement implements LovelaceCard {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._unsubRenderTemplate = subscribeRenderTemplate(
|
try {
|
||||||
|
this._unsubRenderTemplate = await subscribeRenderTemplate(
|
||||||
this.hass.connection,
|
this.hass.connection,
|
||||||
(result) => {
|
(result) => {
|
||||||
this._content = result;
|
this._content = result;
|
||||||
@ -135,10 +136,10 @@ export class HuiMarkdownCard extends LitElement implements LovelaceCard {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
this._unsubRenderTemplate.catch(() => {
|
} catch {
|
||||||
this._content = this._config!.content;
|
this._content = this._config!.content;
|
||||||
this._unsubRenderTemplate = undefined;
|
this._unsubRenderTemplate = undefined;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _tryDisconnect(): Promise<void> {
|
private async _tryDisconnect(): Promise<void> {
|
||||||
@ -147,9 +148,8 @@ export class HuiMarkdownCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const unsub = await this._unsubRenderTemplate;
|
this._unsubRenderTemplate();
|
||||||
this._unsubRenderTemplate = undefined;
|
this._unsubRenderTemplate = undefined;
|
||||||
unsub();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code === "not_found") {
|
if (e.code === "not_found") {
|
||||||
// If we get here, the connection was probably already closed. Ignore.
|
// If we get here, the connection was probably already closed. Ignore.
|
||||||
|
@ -115,6 +115,7 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
|
|||||||
oldConfig.theme !== this._config.theme
|
oldConfig.theme !== this._config.theme
|
||||||
) {
|
) {
|
||||||
applyThemesOnElement(this, this.hass.themes, this._config.theme);
|
applyThemesOnElement(this, this.hass.themes, this._config.theme);
|
||||||
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { LovelaceCard } from "../types";
|
import { LovelaceCard } from "../types";
|
||||||
|
|
||||||
export const computeCardSize = (card: LovelaceCard): number => {
|
export const computeCardSize = (card: LovelaceCard): number => {
|
||||||
return typeof card.getCardSize === "function" ? card.getCardSize() : 1;
|
return typeof card.getCardSize === "function" ? card.getCardSize() : 4;
|
||||||
};
|
};
|
||||||
|
@ -284,16 +284,23 @@ export class HuiCardPicker extends LitElement {
|
|||||||
"ll-rebuild",
|
"ll-rebuild",
|
||||||
(ev) => {
|
(ev) => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
element.parentElement!.replaceChild(
|
this._rebuildCard(element, cardConfig);
|
||||||
this._createCardElement(cardConfig),
|
|
||||||
element
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
{ once: true }
|
{ once: true }
|
||||||
);
|
);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _rebuildCard(
|
||||||
|
cardElToReplace: LovelaceCard,
|
||||||
|
config: LovelaceCardConfig
|
||||||
|
): void {
|
||||||
|
const newCardEl = this._createCardElement(config);
|
||||||
|
if (cardElToReplace.parentElement) {
|
||||||
|
cardElToReplace.parentElement!.replaceChild(newCardEl, cardElToReplace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async _renderCardElement(card: Card): Promise<TemplateResult> {
|
private async _renderCardElement(card: Card): Promise<TemplateResult> {
|
||||||
let { type } = card;
|
let { type } = card;
|
||||||
const { showElement, isCustom, name, description } = card;
|
const { showElement, isCustom, name, description } = card;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user