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 889cb0197..cab3547c2 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 @@ -2099,6 +2099,8 @@ RED.nodes = (function() { activeWorkspace = RED.workspaces.active(); } + const pendingConfigNodes = [] + const pendingConfigNodeIds = new Set() // Find all config nodes and add them for (i=0;iconfig node relationships are + // not very common + let iterationLimit = pendingConfigNodes.length * 5 + const handledConfigNodes = new Set() + while (pendingConfigNodes.length > 0 && iterationLimit > 0) { + const node = pendingConfigNodes.shift() + let hasPending = false + // Loop through the nodes referenced by this node to see if anything + // is pending + node._configNodeReferences.forEach(id => { + if (pendingConfigNodeIds.has(id) && !handledConfigNodes.has(id)) { + // This reference is for a node we know is in this import, but + // it isn't added yet - flag as pending + hasPending = true } + }) + if (!hasPending) { + // This node has no pending config node references - safe to add + delete node._configNodeReferences + new_nodes.push(node) + handledConfigNodes.add(node.id) + } else { + // This node has pending config node references + // Put to the back of the queue + pendingConfigNodes.push(node) } - return count; - }; - new_nodes.sort((a, b) => configNodeFilter(a) - configNodeFilter(b)); + iterationLimit-- + } + if (pendingConfigNodes.length > 0) { + // We exceeded the iteration count. Could be due to reference loops + // between the config nodes. At this point, just add the remaining + // nodes as-is + pendingConfigNodes.forEach(node => { + delete node._configNodeReferences + new_nodes.push(node) + }) + } // Find regular flow nodes and subflow instances for (i=0;i