custom-cards / custom-card-helpers

Custom Card Helper Functions/Types for Developers
https://custom-cards.github.io/custom-card-helpers/
MIT License
48 stars 29 forks source link

createThing: Infinite Recursion #54

Closed michaelhthomas closed 2 years ago

michaelhthomas commented 2 years ago

When calling createThing before hui-error-card has been initialized, there is the potential for infinite recursion. When a component's setConfig method is not yet defined, createThing attempts to create an error card:

try {
  element.setConfig(config);
} catch (err) {
  console.error(tag, err);
  return _createError(err.message, config);
}

If hui-error-card is not yet loaded, the setConfig method does not exist on the error card, causing infinite recursion.

JonahKr commented 2 years ago

Hey there @michaelhthomas 👋

This is an highly unlikely scenario. When loading the hass frontend, at first all the internal cards get loaded. After that custom cards get loaded. That means by the time a custom card gets called upon which uses this library, all internal cards are already loaded.

I agree though that we should check for the functions existance first. Thanks for bringing this up!

Take Care and stay safe!

michaelhthomas commented 2 years ago

Thank you! Somehow, one of my custom cards seemed to be calling createThing before hui-error-card was initialized. Not sure how, but I could typically replicate it by force reloading the page. Subsequent reloads worked just fine most of the time.

JonahKr commented 2 years ago

The question is what the wanted behaviour would be... if it throws an error,the console will get spammed and it eventually won't render at all, If it just returns there is no way to know for the developer what actually happened. Let me know what you think!