Initially, this is my node configurations.
RED.nodes.registerType('HelloWorld', {
category: 'HelloWorld',
defaults: {
firstProp: {value: false}
},
}
This helloworld node is then placed on a flow.
Then, I added another property, secondProp to the configuration and restart node-red.
RED.nodes.registerType('HelloWorld', {
category: 'HelloWorld',
defaults: {
firstProp: {value: false}
secondProp: {value: true}
},
}
When I export the flow, I notice the secondProp is set to false. I had expected it to be set to the default which is true
[
{
"id": "04abe6r5baqs16dc",
...
"firstProp": false,
"secondProp": false, //expected it to be true
"x": 290,
"y": 360
}
]
May I know how do I resolve this and ensure the existing custom nodes on the flow obey the default values of a newly-added property?
NOTE:
When I pull the custom node and place it on the flow, it doesn't have this issue i.e., the secondProp value is true.
One of the node-red maintainer commented
The flow file is not modified just because you modified the custom node src. You would have to handle any in-place upgrades in
oneditprepare. This is normal behaviour as far as I can see.
So as a workaround, we can only do like this
RED.nodes.registerType('HelloWorld', {
category: 'HelloWorld',
defaults: {
firstProp: {value: false}
},
oneditprepare: {
if (this.secondProp === undefined) {
this.secondProp = true;
}
}
}
Note that this will require us to open the edit dialog of the node for it to take effect.