FlowFuse / node-red-dashboard

https://dashboard.flowfuse.com
Apache License 2.0
160 stars 35 forks source link

'Widget load' event triggered only when there is data for the node in the Node-red datastore #793

Open omrid01 opened 2 months ago

omrid01 commented 2 months ago

Current Behavior

Today, when a dashboard 2.0 widget stores its state in the Node-red datastore, when the widget loads (e.g. upon client open or refresh) it will receive a 'widget-load' notification, with a msg object holding the stored data. However, this message is triggered only if the datastore has any data of this node.

Expected Behavior

We need the event to be triggered unconditionally, with an empty msgin case the datastore had no data for the node. The rationale is that if there is no stored state for this widget, we may want to initialize it with some defaults, but while we get an event when there is data, we can never tell that there is no data available.

Steps To Reproduce

No response

Environment

Have you provided an initial effort estimate for this issue?

I have provided an initial effort estimate

joepavitt commented 3 weeks ago

Logic currently prevents the widget-load event firing as it's possible for plugins to clear that object and consequently prevent a message being sent out at all (e.g. if an auth plugin says it's not permitted).

The difficulty here is how we differentiate the plugin removing a msg, and there being no msg in the first place. My thinking is, I need to change the API/pattern for the hooks, and get them to throw errors, and we catch them, to differentiate from a genuine empty msg being sent.