Skip to content

Commit eff70a1

Browse files
authored
fix(client): dead recursion in graph filtering (#992)
1 parent 14d8183 commit eff70a1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/client/src/composables/graph.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,21 +467,26 @@ export function getGraphFilterDataset() {
467467
const node = modulesMap.get(nodeId)
468468
if (!node)
469469
return null
470-
const dataset = recursivelyGetGraphNodeData(nodeId)
470+
const existingNodeIds = new Set<string>()
471+
const dataset = recursivelyGetGraphNodeData(nodeId, existingNodeIds, 0)
471472
return dataset
472473
}
473474

474475
// max depth is 20
475-
function recursivelyGetGraphNodeData(nodeId: string, depth = 0): GraphNodesTotalData[] {
476+
function recursivelyGetGraphNodeData(nodeId: string, existingNodeIds: Set<string>, depth: number): GraphNodesTotalData[] {
477+
if (existingNodeIds.has(nodeId)) {
478+
return []
479+
}
476480
const node = modulesMap.get(nodeId)
477481
depth += 1
478482
if (!node || depth > 20)
479483
return []
480484
const result = [node]
485+
existingNodeIds.add(nodeId)
481486
node.mod.deps.forEach((dep) => {
482487
const node = modulesMap.get(dep)
483488
if (node)
484-
result.push(...recursivelyGetGraphNodeData(node.mod.id, depth))
489+
result.push(...recursivelyGetGraphNodeData(node.mod.id, existingNodeIds, depth))
485490
})
486491
// unique result
487492
return result.reduce<GraphNodesTotalData[]>((prev, node) => {

0 commit comments

Comments
 (0)