Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,18 @@ class ButtonCard extends LitElement {
'grid-area': key,
};
let thing;
if (!deepEqual(this._cardsConfig[key], cards[key])) {
if (
(this._cards[key] as any)?.type === 'error' &&
(this._cards[key] as any)?.error?.includes("Element doesn't exist") &&
cards[key]?.type !== 'error' &&
customElements.get(cards[key]?.type)
) {
// previously errored because element didn't exist, but now it does
thing = this._createCard(cards[key]);
thing.preview = this.preview;
this._cards[key] = thing;
this._cardsConfig[key] = copy(cards[key]);
} else if (!deepEqual(this._cardsConfig[key], cards[key])) {
if (
(this._cardsConfig[key] as any)?.type === cards[key]?.type &&
(this._config!.custom_fields?.[key] as CustomFieldCard)?.force_recreate !== true
Expand Down
8 changes: 6 additions & 2 deletions src/common/create-thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ export const createThing = (cardConfig, isRow = false) => {
if (customElements.get(tag)) return _createThing(tag, cardConfig);

// If element doesn't exist (yet) create an error
const element = _createError(`Custom element doesn't exist: ${cardConfig.type}.`, cardConfig);
const element = _createError(`Element doesn't exist: ${cardConfig.type}.`, cardConfig);
element.style.display = 'None';
const timer = setTimeout(() => {
element.style.display = '';
}, 2000);
// Remove error if element is defined later
customElements.whenDefined(cardConfig.type).then(() => {
// We will get here if cardHelpers were not initially available
// and we are the first to load the lazy loaded element
// as createCardElement in cardHelpers does not await the lazy loaded import
// before trying to create the element.
customElements.whenDefined(tag).then(() => {
clearTimeout(timer);
fireEvent(element, 'll-rebuild', {}, element);
});
Expand Down