Deep clone config#4851
Conversation
| try { | ||
| // @ts-ignore | ||
| element.setConfig(config); | ||
| element.setConfig(deepClone(config)); |
There was a problem hiding this comment.
We shouldn't do this. This hurts our performance because cards are doing the incorrect thing.
Instead we should use Object.freeze and let custom cards crash so they fix their bad behavior. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
There was a problem hiding this comment.
We should freeze it as soon as we load the config.
There was a problem hiding this comment.
Yes, we should deep freeze. Deep freeze example code is on the docs I linked :) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#What_is_shallow_freeze
|
I assume this fixes problems like thomasloven/lovelace-template-entity-row#14? |
|
Yes, but I'll fix that the correct way too. |
|
Closing this in favor of #4862 |

Proposed change
#4509 undid #2496.
Custom cards sometimes change their configuration. This makes sure that change does not propagate back to the global lovelace config.
This also protects against changes caused by bugs in core cards.
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: