Skip to content

Commit

Permalink
fix: only reuse ModuleGraph entry if metadata are deeply equal
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Nov 16, 2022
1 parent f46e558 commit 5f2bfce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"es-module-lexer": "^1.1.0",
"estree-walker": "^3.0.1",
"etag": "^1.8.1",
"fast-deep-equal": "^3.1.3",
"fast-glob": "^3.2.12",
"http-proxy": "^1.18.1",
"json5": "^2.2.1",
Expand Down
7 changes: 5 additions & 2 deletions packages/vite/src/node/server/moduleGraph.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { extname } from 'node:path'
import type { ModuleInfo, PartialResolvedId } from 'rollup'
import deepEqual from 'fast-deep-equal'
import { isDirectCSSRequest } from '../plugins/css'
import {
cleanUrl,
Expand Down Expand Up @@ -183,7 +184,9 @@ export class ModuleGraph {
[url, resolvedId, meta]: ResolvedUrl,
setIsSelfAccepting = true
): ModuleNode {
let mod = this.urlToModuleMap.get(url)
const modForId = this.idToModuleMap.get(resolvedId)
const modForUrl = this.urlToModuleMap.get(url)
let mod = (deepEqual(meta, modForId?.meta) && modForId) || modForUrl
if (!mod) {
mod = new ModuleNode(url, setIsSelfAccepting)
if (meta) mod.meta = meta
Expand All @@ -200,7 +203,7 @@ export class ModuleGraph {
}
// multiple urls can map to the same module and id, make sure we register
// the url to the existing module in that case
else if (!this.urlToModuleMap.has(url)) {
else if (!modForUrl) {
this.urlToModuleMap.set(url, mod)
}
return mod
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f2bfce

Please sign in to comment.