Why is close event not fired on disabled node delete?

Hi Node-RED team, good afternoon, I have a question related to the lifecycle of nodes in the context of developing custom nodes with external services.

When you delete a node, the flow is as follows:

  1. The oneditdelete event is fired on the node configuration running in the editor (frontend).
  2. If you then deploy that flow, the 'close' event is triggered in the node backend, and you can be sure that this node is going to be deleted.

This first flow is okay for me.

In contrast, when you disable and then delete a node, the following occurs:

  1. The close event is triggered in the node backend after the deploy event.
  2. After that, if you delete the node, the oneditdelete event is fired on the node configuration running on the editor (frontend) but if you then perform a new deploy of the flow, you won't be notified of the removal again. I think that, since the removed flag indicates both disabling and removal, it should be fired twice anyway.

Therefore, it would be useful to have the close handler called when a disabled node is deleted.
What's your opinion on this?

Thanks

1 Like

I think this has merit.

Whilst I have not witnessed this myself (through lack of needing to make use of the flag)

If the backend is being passed the reason, it should see both Events.

A node doing magic due to it being disabled only, should also be updated later if removed.

A node might need to remove say some cached data when REALLY no longer needed.

Again - I haven’t witnessed it (I don’t use the flag) - but if it is a thing, then I agree.

calling close twice won't do anything different the second time around - so if you need to clear up you should do it correctly the first time. The oneditdelete event is indeed just for the edit(or) side to remove it from the palette and clean up the front end.

Hi @dceejay, good day, there is a problem related with cleaning when the node gets disabled. The front-end hook is never called and only the close event is fired. In particular, I use that hook to cache nodes to be marked as deleted in the external service that uses this node. Talking in depth, I need the user's access token to able to delete the external service subscription, so I need to have the frontend handler to be called first. In a brief, if I use your approach, I'm also blocked. Anyway, if that's the correct approach, I think it should exist an oneditdisabled hook on the frontend or the oneditdelete should be called on disable.
This last thing makes sense for you?