Junction Node-RED IDs are being duplicated

We have four custom node types registered in Node-RED, two of which have output junctions that serve to connect the output from parent nodes to their child nodes. We require all nodes as well as their output junctions to each have their own unique Node-RED ID. This is indeed the case when these nodes get created, because the new nodes have new IDs assigned to their junctions during the 'oneditprepare' event handling when the node properties are edited.

However, users are also able to copy and paste nodes with their junctions and connected child nodes, and then connect those nodes up elsewhere on the flow tab, without having to edit the node properties. When a node and its junctions are copied and left unedited, there is no event that fires, which we can trap and to which we can assign a handler function. This causes a problem whereby nodes are copied with their original Node-RED IDs still intact, resulting in nodes on the flow tab with duplicate Node-RED IDs. Is there an 'oneditcopy' or 'oneditpaste' event, or something similar, which would enable us to detect a node copy event, or to control what happens to copied node junctions when they are pasted or imported into the workspace?

Hi Elaine to the forum.

Can you explain what do you mean by output junction? Do you mean the circular output ports on the right hand side of a node?

Also, what & why would you need these to have an ID? Are you tagging messages that leave the port with this ID? Are you doing something else in your custom nudes that attempt to inhibit or alert the user about what nodes they can/should connect? Essentially, I'm asking what is the purpose of these ID?

Lastly, are these custom nodes available to all (on GitHub/npm) or internal/private/propitiatory?

Yes, with 'junction' I mean 'the circular output ports on the right hand side of a node'. The custom nodes are proprietary, so I am unable to expand too broadly on the reason for the ID assignment to the junctions, other than to say that upon deployment, the flow node JSON model is exported and reprocessed by a legacy back-end. Removing the junction IDs would require very significant refactoring downstream. It is an option, I agree, but rather invasive and definitely not our first choice.

Fair enough.

As you cannot divulge more, it will be hard for us to provide potential alternative solutions or advise tbh.

As I'm sure you know, the only events available in the node are listed here: Node properties : Node-RED

I think others in the past have hooked into an import event (which a paste operation calls) but I can't remember the details right now. Perhaps that is a clue to start searching the forum.

Alternatively, you might need to build a plug in that hooks into internal events emitted by RED.events (you can find these by searching the source)

That sounds promising. Thank you.

Reading the thread again, I am probably not helping, but on the remote chance it may help I won't delete it just now.

Which version of NR are you using?

If an early version there is a node called fan which may be handy.

But if it is a more recent version, there is a new feature you can use which is called the joint.

Does that help?

If you check the following code, you can see the standard code I use for my uibuilder nodes. Some of them HAVE to empty a key field when nodes are copy/pasted or imported so I came up with a standard function to do it that gets loaded into all of my nodes Editor html files.

You should be able to adapt for your own use. Lines 158-162 are the key ones.

Thanks Julian, I thought it was yourself that did something in this area (I just didn't wanna tag you unnecessarily)

1 Like

Thank you. I've learned that copying and pasting a node and its junctions and child nodes in the editor, raises a nodes:add event. Adding a handler function for such an event enabled me to incept those nodes as they are pasted, and to interrogate the node data. I have managed to resolve my junction ID issue.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.