Skip to content

Commit 41e437f

Browse files
authored
perf(hmr): skip traversed modules when checking circular imports (#15034)
1 parent dc494ad commit 41e437f

File tree

1 file changed

+8
-0
lines changed
  • packages/vite/src/node/server

1 file changed

+8
-0
lines changed

packages/vite/src/node/server/hmr.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,13 @@ function propagateUpdate(
361361
* @param nodeChain The chain of nodes/imports that lead to the node.
362362
* (The last node in the chain imports the `node` parameter)
363363
* @param currentChain The current chain tracked from the `node` parameter
364+
* @param traversedModules The set of modules that have traversed
364365
*/
365366
function isNodeWithinCircularImports(
366367
node: ModuleNode,
367368
nodeChain: ModuleNode[],
368369
currentChain: ModuleNode[] = [node],
370+
traversedModules = new Set<ModuleNode>(),
369371
): HasDeadEnd {
370372
// To help visualize how each parameters work, imagine this import graph:
371373
//
@@ -383,6 +385,11 @@ function isNodeWithinCircularImports(
383385
// It works by checking if any `node` importers are within `nodeChain`, which
384386
// means there's an import loop with a HMR-accepted module in it.
385387

388+
if (traversedModules.has(node)) {
389+
return false
390+
}
391+
traversedModules.add(node)
392+
386393
for (const importer of node.importers) {
387394
// Node may import itself which is safe
388395
if (importer === node) continue
@@ -416,6 +423,7 @@ function isNodeWithinCircularImports(
416423
importer,
417424
nodeChain,
418425
currentChain.concat(importer),
426+
traversedModules,
419427
)
420428
if (result) return result
421429
}

0 commit comments

Comments
 (0)