Skip to content

Commit

Permalink
Safety check for customelements.define
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Dec 27, 2023
1 parent fd5aa3e commit bb1612b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion card-mod.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/card-mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ export class CardMod extends LitElement {
}

(async () => {
customElements.define("card-mod", CardMod);
if (!customElements.get("card-mod")) {
customElements.define("card-mod", CardMod);
}

// Wait for scoped customElements registry to be set up
// and then redefine card-mod if necessary
Expand Down
4 changes: 3 additions & 1 deletion src/mod-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ class ModCard extends LitElement {

(async () => {
// See explanation in card-mod.ts
customElements.define("mod-card", ModCard);
if (!customElements.get("mod-card")) {
customElements.define("mod-card", ModCard);
}
while (customElements.get("home-assistant") === undefined)
await new Promise((resolve) => window.setTimeout(resolve, 100));

Expand Down

0 comments on commit bb1612b

Please sign in to comment.