From 6fbcec8b983f4d66874e8a8eaa4c4d1a83b07141 Mon Sep 17 00:00:00 2001 From: Gerwin van Beek Date: Mon, 24 Apr 2023 11:51:06 +0200 Subject: [PATCH 1/2] Solved node red not loading without error when subflow is missing --- .../@node-red/editor-client/src/js/nodes.js | 29 +++++++++++++------ .../editor-client/src/js/ui/editor.js | 10 ++++--- .../@node-red/runtime/lib/flows/util.js | 2 +- 3 files changed, 27 insertions(+), 14 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 865636b24..94bdbfcf7 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 @@ -2095,16 +2095,27 @@ RED.nodes = (function() { } else if (n.type.substring(0,7) === "subflow") { var parentId = n.type.split(":")[1]; var subflow = subflow_denylist[parentId]||subflow_map[parentId]||getSubflow(parentId); - if (createNewIds || options.importMap[n.id] === "copy") { - parentId = subflow.id; - node.type = "subflow:"+parentId; - node._def = registry.getNodeType(node.type); - delete node.i; + if (!subflow){ + node._def = { + color:"#fee", + defaults: {}, + label: "unknown: "+n.type, + labelStyle: "red-ui-flow-node-label-italic", + outputs: n.outputs|| (n.wires && n.wires.length) || 0, + set: registry.getNodeSet("node-red/unknown") + } + } else { + if (createNewIds || options.importMap[n.id] === "copy") { + parentId = subflow.id; + node.type = "subflow:"+parentId; + node._def = registry.getNodeType(node.type); + delete node.i; + } + node.name = n.name; + node.outputs = subflow.out.length; + node.inputs = subflow.in.length; + node.env = n.env; } - node.name = n.name; - node.outputs = subflow.out.length; - node.inputs = subflow.in.length; - node.env = n.env; } else if (n.type === 'junction') { node._def = {defaults:{}} node._config.x = node.x diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js index da7954625..188819734 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js @@ -45,11 +45,13 @@ RED.editor = (function() { var hasChanged; if (node.type.indexOf("subflow:")===0) { subflow = RED.nodes.subflow(node.type.substring(8)); - isValid = subflow.valid; - hasChanged = subflow.changed; - if (isValid === undefined) { - isValid = validateNode(subflow); + if (subflow){ + isValid = subflow.valid; hasChanged = subflow.changed; + if (isValid === undefined) { + isValid = validateNode(subflow); + hasChanged = subflow.changed; + } } validationErrors = validateNodeProperties(node, node._def.defaults, node); node.valid = isValid && validationErrors.length === 0; diff --git a/packages/node_modules/@node-red/runtime/lib/flows/util.js b/packages/node_modules/@node-red/runtime/lib/flows/util.js index 7c98fc041..74e046f45 100644 --- a/packages/node_modules/@node-red/runtime/lib/flows/util.js +++ b/packages/node_modules/@node-red/runtime/lib/flows/util.js @@ -199,7 +199,7 @@ function parseConfig(config) { if (subflowDetails) { var subflowType = subflowDetails[1] n.subflow = subflowType; - flow.subflows[subflowType].instances.push(n) + if (flow.subflows[subflowType]) flow.subflows[subflowType].instances.push(n) } if (container) { container.nodes[n.id] = n; From 841f1849c8b38a4a32ac996ffab916bb20744a20 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 28 Apr 2023 15:25:29 +0100 Subject: [PATCH 2/2] Update packages/node_modules/@node-red/runtime/lib/flows/util.js --- packages/node_modules/@node-red/runtime/lib/flows/util.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/runtime/lib/flows/util.js b/packages/node_modules/@node-red/runtime/lib/flows/util.js index 74e046f45..83665b589 100644 --- a/packages/node_modules/@node-red/runtime/lib/flows/util.js +++ b/packages/node_modules/@node-red/runtime/lib/flows/util.js @@ -199,7 +199,9 @@ function parseConfig(config) { if (subflowDetails) { var subflowType = subflowDetails[1] n.subflow = subflowType; - if (flow.subflows[subflowType]) flow.subflows[subflowType].instances.push(n) + if (flow.subflows[subflowType]) { + flow.subflows[subflowType].instances.push(n) + } } if (container) { container.nodes[n.id] = n;