From 2c4dc3334d753d68cd2cfbe4ba839f08628c7b0c Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:46:48 +0200 Subject: [PATCH 1/2] Fix subflow outbound-link filter --- .../@node-red/editor-client/src/js/nodes.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 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 2a7b440f2..84a290b59 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,12 +2406,15 @@ 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); - }); + // If importing a subflow, ensure an outbound-link doesn't get added + if (/^link /.test(n.type) && n.links) { + const isSubflow = !!getSubflow(n.z); + if (isSubflow) { + n.links = n.links.filter(function(id) { + const otherNode = node_map[id] || RED.nodes.node(id); + return (otherNode && otherNode.z === n.z); + }); + } } for (var d3 in n._def.defaults) { if (n._def.defaults.hasOwnProperty(d3)) { From 912a30b28de344876f687324d26ce442962b837d Mon Sep 17 00:00:00 2001 From: Gauthier Dandele <92022724+GogoVega@users.noreply.github.com> Date: Wed, 11 Sep 2024 17:02:18 +0200 Subject: [PATCH 2/2] Improve the filter to handle all cases + comments Co-authored-by: Nick O'Leary --- .../@node-red/editor-client/src/js/nodes.js | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 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 84a290b59..dacd6eeae 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,15 +2406,25 @@ RED.nodes = (function() { } else { delete n.g } - // If importing a subflow, ensure an outbound-link doesn't get added + // If importing a link node, ensure both ends of each link are either: + // - not in a subflow + // - both in the same subflow if (/^link /.test(n.type) && n.links) { - const isSubflow = !!getSubflow(n.z); - if (isSubflow) { - n.links = n.links.filter(function(id) { - const otherNode = node_map[id] || RED.nodes.node(id); - return (otherNode && otherNode.z === n.z); - }); - } + n.links = n.links.filter(function(id) { + const otherNode = node_map[id] || RED.nodes.node(id); + if (!otherNode) { + // Cannot find other end - remove the link + return false + } + if (otherNode.z === n.z) { + // Both ends in the same flow/subflow + return true + } else if (!!getSubflow(n.z) || !!getSubflow(otherNode.z)) { + // One end is in a subflow - remove the link + return false + } + return true + }); } for (var d3 in n._def.defaults) { if (n._def.defaults.hasOwnProperty(d3)) {