Looks like the construction / destruction sequence was changed, perhaps with 2.0?
How it used to be:
Construction order: module, widget, dataFromJson, onAdd
Destruction order: dataToJson, onRemove, widget, module
How it is now:
Construction order: [module, dataFromJson, onAdd], [widget]
Destruction order: [dataToJson], [widget, onRemove, module]
(Square brackets suggest grouping of calls, when you have multiple instances. Not sure how that used to be.)
That means you could rely on the fact that in onAdd/onRemove the module and the widget were constructed, had loaded params and were in the engine. Everything was in place, no dangling ends. You could do any further initialization you fancied.
Not so anymore. For instance, output port initialization based on saved states will be overwritten by the engine, if you do it in dataFromJson or onAdd. You have to call back into the module from the widget constructor to do such things. Or initializing custom widgets must now be done the other way around. In one of my modules, there’s data shared between instances, which I used to update in onAdd/onRemove. Haven’t checked yet how that behaves now.
Was there any reason for this change? Can it be reversed? What’s the intended purpose of onAdd/onRemove? They seem pretty much useless now.