File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
packages/client/src/composables Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff 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 ) => {
You can’t perform that action at this time.
0 commit comments