Skip to content

Commit

Permalink
Use set of strings instead of modules
Browse files Browse the repository at this point in the history
  • Loading branch information
skovhus committed Nov 20, 2023
1 parent 3cc24a0 commit bdb5362
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ function propagateUpdate(
* @param nodeChain The chain of nodes/imports that lead to the node.
* (The last node in the chain imports the `node` parameter)
* @param currentChain The current chain tracked from the `node` parameter
* @param traversedModules The set of modules that have been traversed
* @param traversedModuleUrls The set of modules URLs that have been traversed
*/
function isNodeWithinCircularImports(
node: ModuleNode,
nodeChain: ModuleNode[],
currentChain: ModuleNode[] = [node],
traversedModules = new Set<ModuleNode>(),
traversedModuleUrls = new Set<string>(),
): HasDeadEnd {
// To help visualize how each parameters work, imagine this import graph:
//
Expand All @@ -385,11 +385,10 @@ function isNodeWithinCircularImports(
// It works by checking if any `node` importers are within `nodeChain`, which
// means there's an import loop with a HMR-accepted module in it.

if (traversedModules.has(node)) {
// To avoid infinite recursion, we only check each module once.
if (traversedModuleUrls.has(node.url)) {
return false
}
traversedModules.add(node)
traversedModuleUrls.add(node.url)

for (const importer of node.importers) {
// Node may import itself which is safe
Expand Down Expand Up @@ -424,7 +423,7 @@ function isNodeWithinCircularImports(
importer,
nodeChain,
currentChain.concat(importer),
traversedModules,
traversedModuleUrls,
)
if (result) return result
}
Expand Down

0 comments on commit bdb5362

Please sign in to comment.