diff --git a/packages/node_modules/@node-red/editor-client/src/js/nodes.js b/packages/node_modules/@node-red/editor-client/src/js/nodes.js index c24d95bc0..d9ef6ab44 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/nodes.js +++ b/packages/node_modules/@node-red/editor-client/src/js/nodes.js @@ -1306,21 +1306,23 @@ RED.nodes = (function() { RED.events.on("registry:node-type-added",function(type) { var def = registry.getNodeType(type); var replaced = false; - var replaceNodes = []; + var replaceNodes = {}; RED.nodes.eachNode(function(n) { if (n.type === "unknown" && n.name === type) { - replaceNodes.push(n); + replaceNodes[n.id] = n; } }); RED.nodes.eachConfig(function(n) { if (n.type === "unknown" && n.name === type) { - replaceNodes.push(n); + replaceNodes[n.id] = n; } }); - if (replaceNodes.length > 0) { + var replaceNodeIds = Object.keys(replaceNodes); + if (replaceNodeIds.length > 0) { var reimportList = []; - replaceNodes.forEach(function(n) { + replaceNodeIds.forEach(function(id) { + var n = replaceNodes[id]; if (configNodes.hasOwnProperty(n.id)) { delete configNodes[n.id]; } else { @@ -1328,6 +1330,18 @@ RED.nodes = (function() { } reimportList.push(convertNode(n)); }); + + // Remove any links between nodes that are going to be reimported. + // This prevents a duplicate link from being added. + var removeLinks = []; + RED.nodes.eachLink(function(l) { + if (replaceNodes.hasOwnProperty(l.source.id) && replaceNodes.hasOwnProperty(l.target.id)) { + removeLinks.push(l); + } + }); + removeLinks.forEach(removeLink); + + RED.view.redraw(true); var result = importNodes(reimportList,false); var newNodeMap = {};