Skip to content

fix: Fix custom element does not exist error which may arise under specific circumstances#1152

Draft
dcapslock wants to merge 1 commit into
custom-cards:devfrom
dcapslock:fix-lazy-load-card-scenarios
Draft

fix: Fix custom element does not exist error which may arise under specific circumstances#1152
dcapslock wants to merge 1 commit into
custom-cards:devfrom
dcapslock:fix-lazy-load-card-scenarios

Conversation

@dcapslock

Copy link
Copy Markdown
Collaborator

Fixes #1150

This is hard to replicate. To do so I set the initial values of helpers to undefined and then delayed calling the helperPromise in _createCard. Even then it only happens for me 1 out of 10 or so.

This PR may not be the best way. The crux of the matter is that Frontend does not await import of lazy loaded stock cards like it does for dialogs. Perhaps createThing is not needed anymore and solely rely on createCardElement and only show 'Loading...' while cardHelpers are not defined, allowing the recovery logic in createCardElement to handle the lazy loading, which it does, including recovering from not awaiting the import.

The PR as is provides for least risk as far as changes to button-card. However I am happy to look for alternatives. Two in mind:

  1. Use createCardElemenet only and warp in a promise to allow for cardHelpers not to be available, and use ${until(thing), "Loading..."} or
  2. Switch over to load cards via hui-card method where everything is abstracted to Frontend. e.g. as per my update to auto-entities. Similar method used with expander-card. The only caveat here is the extra hui-card wrapper which may break card-mod config users have, and perhaps other things I have not thought of.

PR in draft to allow for discussion.

@RomRider

Copy link
Copy Markdown
Collaborator

I don't really understand why this is happening (lack of enough javascript knowledge...), but if the proper way to fix this once and for all is to load cards through hui-card, I think we should go this way.

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