From eb866d59d381accc4b1283de599266a9246ff91a Mon Sep 17 00:00:00 2001 From: Rizumu Ayaka Date: Tue, 4 Nov 2025 15:35:07 +0900 Subject: [PATCH] fix: dead recursion in graph filtering --- packages/client/src/composables/graph.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/client/src/composables/graph.ts b/packages/client/src/composables/graph.ts index d94d5ce61..db7408546 100644 --- a/packages/client/src/composables/graph.ts +++ b/packages/client/src/composables/graph.ts @@ -467,21 +467,26 @@ export function getGraphFilterDataset() { const node = modulesMap.get(nodeId) if (!node) return null - const dataset = recursivelyGetGraphNodeData(nodeId) + const existingNodeIds = new Set() + const dataset = recursivelyGetGraphNodeData(nodeId, existingNodeIds, 0) return dataset } // max depth is 20 -function recursivelyGetGraphNodeData(nodeId: string, depth = 0): GraphNodesTotalData[] { +function recursivelyGetGraphNodeData(nodeId: string, existingNodeIds: Set, depth: number): GraphNodesTotalData[] { + if (existingNodeIds.has(nodeId)) { + return [] + } const node = modulesMap.get(nodeId) depth += 1 if (!node || depth > 20) return [] const result = [node] + existingNodeIds.add(nodeId) node.mod.deps.forEach((dep) => { const node = modulesMap.get(dep) if (node) - result.push(...recursivelyGetGraphNodeData(node.mod.id, depth)) + result.push(...recursivelyGetGraphNodeData(node.mod.id, existingNodeIds, depth)) }) // unique result return result.reduce((prev, node) => {