postlund/search-card

⚠️ Information: Future card configuration changes.

thomasloven opened this issue · 6 comments

Hi.

A change in how lovelace cards are set up in Home Assistant 0.105 increases performance, but enables cards to accidentally modify their own configuration in the loaded lovelace configuration.

I'm going through the cards in the HACS default repository, and noticed that your card may be susceptible to this. Looking through your code it seems you may modify parts of the config object passed to your card in setConfig.

The result could be that your card does not work well with the GUI editors or that parts of the configuration start showing up multiple times.

At some point in the future, it is likely that the configuration will be frozen before being passed to setConfig. At this point, your card will fail entirely when it tries to modify the configuration object.

There are several ways to fix/protect agains this problem.

The best is to restructure setConfig such that the configuration is never modified.
Other alternatives are to make a copy of the configuration and work on that instead.

setConfig(config) {
  config = { ...config }; // This works for simple configurations not containing arrays or objects
...
import { deepClone } from "deep-clone-simple";
// https://github.com/balloob/deep-clone-simple

setConfig(config) {
  config = deepClone(config); // This is a safe and fast method
...

or

setConfig(config) {
  config = JSON.parse(JSON.stringify(config)); // This uses built-in functions, but may be slower than deepClone
  ...

Please note that I have not tested your card agains Home Assistant 0.105 or later, but just quickly looked through the code. If I'm mistaken in my assessment, I appologize for taking your time.

See thomasloven/hass-config#6 for more info.

Also see #16

You are not mistaken, the card no longer loads on HA 0.106.0b0.

I'll see if I can fix it tonight. All my energy has been on getting the Apple TV integration out the door.

Ah yeah, I had completely forgotten about that one. (Still using the modified version from chamberlain) thanks for this amazing card btw!

The new Apple TV component will hopefully land very soon.

I have updated the card now so it should work. Can you give it a try @jimz011?

Works like a charm, 🙏. Good to hear the atv component will make its comeback.

Great! Yeah, nice to have it restored again.