Skip to content

Register the card in the registry the frontend actually uses - #22

Merged
GhostTypes merged 1 commit into
GhostTypes:mainfrom
RedAces:fix/card-registry-timing
Aug 5, 2026
Merged

Register the card in the registry the frontend actually uses#22
GhostTypes merged 1 commit into
GhostTypes:mainfrom
RedAces:fix/card-registry-timing

Conversation

@RedAces

@RedAces RedAces commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Home Assistant replaces window.customElements with its own scoped registry while it boots. add_extra_js_url puts the card in the document, so it ran before that swap and defined its elements in a registry the frontend then stopped consulting.

The failure was silent: define() succeeded, the module was served with 200 and text/javascript, the banner printed, and window.customCards listed the card because that lives on window rather than on the registry. But customElements.get() returned undefined, the picker did not offer the card, and dashboards using it showed "custom element doesn't exist". Re-importing the identical file after boot worked without raising "already defined", which identified the two registries.

Registration now goes through a guarded helper and is repeated when the registry object is exchanged, so a browser that never swaps still registers exactly once. Observed on HA 2026.7.4 with Firefox; adding the card as a Lovelace resource was the workaround, since resources load after the boot.

Home Assistant replaces window.customElements with its own scoped registry
while it boots. add_extra_js_url puts the card in the document, so it ran
before that swap and defined its elements in a registry the frontend then
stopped consulting.

The failure was silent: define() succeeded, the module was served with 200 and
text/javascript, the banner printed, and window.customCards listed the card
because that lives on window rather than on the registry. But
customElements.get() returned undefined, the picker did not offer the card, and
dashboards using it showed "custom element doesn't exist". Re-importing the
identical file after boot worked without raising "already defined", which
identified the two registries.

Registration now goes through a guarded helper and is repeated when the
registry object is exchanged, so a browser that never swaps still registers
exactly once. Observed on HA 2026.7.4 with Firefox; adding the card as a
Lovelace resource was the workaround, since resources load after the boot.
@GhostTypes
GhostTypes merged commit ceab425 into GhostTypes:main Aug 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants