-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: data missing from moduleInfo.meta #7477
base: main
Are you sure you want to change the base?
Changes from 8 commits
f46e558
5f2bfce
a75bf4e
8307b3a
a2fead6
75be95f
f63979b
6df09d0
c8acbea
a89374c
41cbca0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -508,7 +508,7 @@ export async function createServer( | |
ws.on('vite:invalidate', async ({ path }: InvalidatePayload) => { | ||
const mod = moduleGraph.urlToModuleMap.get(path) | ||
if (mod && mod.isSelfAccepting && mod.lastHMRTimestamp > 0) { | ||
const file = getShortName(mod.file!, config.root) | ||
const file = getShortName(mod.file, config.root) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactor: Removing nullability of |
||
updateModules(file, [...mod.importers], mod.lastHMRTimestamp, server) | ||
} | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { extname } from 'node:path' | ||
import type { ModuleInfo, PartialResolvedId } from 'rollup' | ||
import deepEqual from 'fast-deep-equal' | ||
import { isDirectCSSRequest } from '../plugins/css' | ||
import { | ||
cleanUrl, | ||
normalizePath, | ||
removeDepVersionQuery, | ||
removeImportQuery, | ||
removeTimestampQuery | ||
} from '../utils' | ||
|
@@ -15,11 +17,11 @@ export class ModuleNode { | |
* Public served url path, starts with / | ||
*/ | ||
url: string | ||
file: string | ||
/** | ||
* Resolved file system path + query | ||
*/ | ||
id: string | null = null | ||
file: string | null = null | ||
type: 'js' | 'css' | ||
info?: ModuleInfo | ||
meta?: Record<string, any> | ||
|
@@ -37,14 +39,14 @@ export class ModuleNode { | |
lastInvalidationTimestamp = 0 | ||
|
||
/** | ||
* @param setIsSelfAccepting - set `false` to set `isSelfAccepting` later. e.g. #7870 | ||
* @param allowHmrPropagation - set `isSelfAccepting` to false to ensure it's | ||
* never undefined (which prevents HMR update propagation, see #7870) | ||
*/ | ||
constructor(url: string, setIsSelfAccepting = true) { | ||
constructor(url: string, file: string, isSelfAccepting?: boolean) { | ||
this.url = url | ||
this.file = file | ||
this.type = isDirectCSSRequest(url) ? 'css' : 'js' | ||
if (setIsSelfAccepting) { | ||
this.isSelfAccepting = false | ||
} | ||
this.isSelfAccepting = isSelfAccepting | ||
} | ||
} | ||
|
||
|
@@ -87,7 +89,8 @@ export class ModuleGraph { | |
} | ||
|
||
getModuleById(id: string): ModuleNode | undefined { | ||
return this.idToModuleMap.get(removeTimestampQuery(id)) | ||
const unhashedId = removeDepVersionQuery(id) | ||
return this.idToModuleMap.get(unhashedId) || this.idToModuleMap.get(id) | ||
} | ||
|
||
getModulesByFile(file: string): Set<ModuleNode> | undefined { | ||
|
@@ -149,7 +152,7 @@ export class ModuleGraph { | |
for (const imported of importedModules) { | ||
const dep = | ||
typeof imported === 'string' | ||
? await this.ensureEntryFromUrl(imported, ssr) | ||
? this.urlToModuleMap.get(imported)! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything in |
||
: imported | ||
dep.importers.add(mod) | ||
nextImports.add(dep) | ||
|
@@ -169,7 +172,7 @@ export class ModuleGraph { | |
for (const accepted of acceptedModules) { | ||
const dep = | ||
typeof accepted === 'string' | ||
? await this.ensureEntryFromUrl(accepted, ssr) | ||
? await this.ensureEntryFromUrl(accepted, ssr, false) | ||
: accepted | ||
deps.add(dep) | ||
} | ||
|
@@ -179,20 +182,33 @@ export class ModuleGraph { | |
return noLongerImported | ||
} | ||
|
||
async ensureEntryFromUrl( | ||
rawUrl: string, | ||
ssr?: boolean, | ||
setIsSelfAccepting = true | ||
): Promise<ModuleNode> { | ||
const [url, resolvedId, meta] = await this.resolveUrl(rawUrl, ssr) | ||
let mod = this.idToModuleMap.get(resolvedId) | ||
ensureEntryFromResolved( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new method that allows adding a module node without calling |
||
[url, resolvedId, meta]: ResolvedUrl, | ||
isSelfAccepting?: boolean | ||
): ModuleNode { | ||
const unhashedId = removeDepVersionQuery(resolvedId) | ||
if (this.idToModuleMap.has(unhashedId)) { | ||
resolvedId = unhashedId | ||
Comment on lines
+189
to
+191
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to strip the version query here and see if a module node exists without, as we can't safely remove it from inside |
||
} | ||
const modForId = this.idToModuleMap.get(resolvedId) | ||
const modForUrl = this.urlToModuleMap.get(url) | ||
|
||
// When metadata is derived from the browser URL, we cannot reuse the module | ||
// node for the resolved Rollup id, as load/transform hooks may use the | ||
// metadata to produce a different result. | ||
let mod = (deepEqual(meta, modForId?.meta) && modForId) || modForUrl | ||
|
||
if (!mod) { | ||
mod = new ModuleNode(url, setIsSelfAccepting) | ||
if (meta) mod.meta = meta | ||
this.urlToModuleMap.set(url, mod) | ||
const file = cleanUrl(resolvedId) | ||
mod = new ModuleNode(url, file, isSelfAccepting) | ||
mod.id = resolvedId | ||
this.idToModuleMap.set(resolvedId, mod) | ||
const file = (mod.file = cleanUrl(resolvedId)) | ||
if (meta) { | ||
mod.meta = meta | ||
} | ||
this.urlToModuleMap.set(url, mod) | ||
if (!modForId) { | ||
this.idToModuleMap.set(resolvedId, mod) | ||
} | ||
let fileMappedModules = this.fileToModulesMap.get(file) | ||
if (!fileMappedModules) { | ||
fileMappedModules = new Set() | ||
|
@@ -202,12 +218,22 @@ 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 | ||
} | ||
|
||
async ensureEntryFromUrl( | ||
rawUrl: string, | ||
ssr?: boolean, | ||
isSelfAccepting?: boolean | ||
): Promise<ModuleNode> { | ||
const resolved = await this.resolveUrl(rawUrl, ssr) | ||
return this.ensureEntryFromResolved(resolved, isSelfAccepting) | ||
} | ||
|
||
// some deps, like a css file referenced via @import, don't have its own | ||
// url because they are inlined into the main css import. But they still | ||
// need to be represented in the module graph so that they can trigger | ||
|
@@ -227,8 +253,7 @@ export class ModuleGraph { | |
} | ||
} | ||
|
||
const mod = new ModuleNode(url) | ||
mod.file = file | ||
const mod = new ModuleNode(url, file) | ||
fileMappedModules.add(mod) | ||
return mod | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactor: The default value of
isSelfAccepting
is now undefined, so we need to pass an explicitfalse
value wherever nothing was previously passed.