@@ -122,12 +122,13 @@ async function buildRouterGraphInternal(
122122 }
123123
124124 // Prevent infinite recursion on circular imports
125- if ( visited . has ( entryFileUri ) ) {
126- log ( `Skipping already visited file: "${ entryFileUri } "` )
125+ const visitedKey = `${ entryFileUri } #${ targetVariable ?? "" } `
126+ if ( visited . has ( visitedKey ) ) {
127+ log ( `Skipping already visited: "${ visitedKey } "` )
127128 return null
128129 }
129130
130- visited . add ( entryFileUri )
131+ visited . add ( visitedKey )
131132
132133 // Helper to analyze a file with the filesystem
133134 const analyzeFileFn = ( uri : string ) => analyzeFile ( uri , parser , fs )
@@ -361,11 +362,13 @@ async function resolveRouterReference(
361362 ( r ) => r . variableName === attributeName ,
362363 )
363364 if ( targetRouter ) {
365+ const visitedKey = `${ importedFileUri } #${ attributeName } `
366+
364367 // Mark as visited to prevent infinite recursion
365- if ( visited . has ( importedFileUri ) ) {
368+ if ( visited . has ( visitedKey ) ) {
366369 return null
367370 }
368- visited . add ( importedFileUri )
371+ visited . add ( visitedKey )
369372
370373 // Get routes belonging to this router
371374 const routerRoutes = importedAnalysis . routes . filter (
@@ -387,8 +390,9 @@ async function resolveRouterReference(
387390
388391 return routerNode
389392 }
390- // If not found as a router, fall through to try building from file
391393 }
392394
393- return buildRouterGraphInternal ( importedFileUri , ctx )
395+ // Resolve by variable name for named imports, or fall back to full-file discovery
396+ const targetVarName = namedImport ? originalName : undefined
397+ return buildRouterGraphInternal ( importedFileUri , ctx , targetVarName )
394398}
0 commit comments