From 476016cbcc08840f0b444bd378b225734e4ec00e Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Wed, 5 Jun 2024 12:22:22 +0200 Subject: [PATCH 1/3] Fix `node_map` does not contain as key the new id of a copied node --- .../node_modules/@node-red/editor-client/src/js/nodes.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 54c89157a..c9f78cb25 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 @@ -2406,8 +2406,9 @@ RED.nodes = (function() { // get added if (activeSubflow && /^link /.test(n.type) && n.links) { n.links = n.links.filter(function(id) { - const otherNode = node_map[id] || RED.nodes.node(id); - return (otherNode && otherNode.z === activeWorkspace) + const otherNodeInMap = Object.values(node_map).filter(function(n) { return n.id === id; }); + const otherNode = (otherNodeInMap.length ? otherNodeInMap[0] : null) || RED.nodes.node(id); + return (otherNode && otherNode.z === activeWorkspace); }); } } From 1d342a778d1c95cb115459c43eda9cc6c19a1f64 Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:12:35 +0200 Subject: [PATCH 2/3] Fix `new_nodes` should be used instead of `node_map` --- packages/node_modules/@node-red/editor-client/src/js/nodes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 c9f78cb25..adc852068 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 @@ -2406,8 +2406,8 @@ RED.nodes = (function() { // get added if (activeSubflow && /^link /.test(n.type) && n.links) { n.links = n.links.filter(function(id) { - const otherNodeInMap = Object.values(node_map).filter(function(n) { return n.id === id; }); - const otherNode = (otherNodeInMap.length ? otherNodeInMap[0] : null) || RED.nodes.node(id); + const nodeImported = new_nodes.filter(function(n) { return n.id === id; }); + const otherNode = (nodeImported.length ? nodeImported[0] : null) || RED.nodes.node(id); return (otherNode && otherNode.z === activeWorkspace); }); } From bb91a0893900782caf1b8dad488d7555a3f6c016 Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:28:30 +0200 Subject: [PATCH 3/3] Just move the block before the Id is updated --- .../@node-red/editor-client/src/js/nodes.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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 adc852068..3783c804b 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 @@ -2379,6 +2379,13 @@ RED.nodes = (function() { } else { delete n.g } + // If importing into a subflow, ensure an outbound-link doesn't get added + if (activeSubflow && /^link /.test(n.type) && n.links) { + n.links = n.links.filter(function(id) { + const otherNode = node_map[id] || RED.nodes.node(id); + return (otherNode && otherNode.z === activeWorkspace); + }); + } for (var d3 in n._def.defaults) { if (n._def.defaults.hasOwnProperty(d3)) { if (n._def.defaults[d3].type) { @@ -2402,15 +2409,6 @@ RED.nodes = (function() { } } } - // If importing into a subflow, ensure an outbound-link doesn't - // get added - if (activeSubflow && /^link /.test(n.type) && n.links) { - n.links = n.links.filter(function(id) { - const nodeImported = new_nodes.filter(function(n) { return n.id === id; }); - const otherNode = (nodeImported.length ? nodeImported[0] : null) || RED.nodes.node(id); - return (otherNode && otherNode.z === activeWorkspace); - }); - } } for (i=0;i