Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Card configuration change #6

Open
92 tasks done
thomasloven opened this issue Feb 13, 2020 · 2 comments
Open
92 tasks done

Card configuration change #6

thomasloven opened this issue Feb 13, 2020 · 2 comments

Comments

@thomasloven
Copy link
Owner

thomasloven commented Feb 13, 2020

More info: home-assistant/frontend#4862

@thomasloven
Copy link
Owner Author

thomasloven commented Feb 13, 2020

⚠️ Information: Future card configuration changes.

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 #6 for more info.

@thomasloven
Copy link
Owner Author

thomasloven commented Feb 13, 2020

FAQ

Is my card ok if it's checked off on this list and I didn't get an issue?

Not necessarily. I only looked at your source very quickly.

Is Object.assign({ }, config) ok?

That's the same thing as {...config}. It will work for most simple configurations.

This was referenced Feb 13, 2020
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

No branches or pull requests

1 participant