invalidateModule() — vite Function Reference
Architecture documentation for the invalidateModule() function in moduleGraph.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 9eb17063_e0f2_709b_4eff_fdea32177425["invalidateModule()"] cdb618b6_fede_c732_1a58_98b86b491151["EnvironmentModuleGraph"] 9eb17063_e0f2_709b_4eff_fdea32177425 -->|defined in| cdb618b6_fede_c732_1a58_98b86b491151 dd164f22_a6d3_7e8d_43c3_45e219e70176["invalidateModule()"] dd164f22_a6d3_7e8d_43c3_45e219e70176 -->|calls| 9eb17063_e0f2_709b_4eff_fdea32177425 f3ee260b_149d_7a3c_7489_7c6e940fce67["invalidateModule()"] f3ee260b_149d_7a3c_7489_7c6e940fce67 -->|calls| 9eb17063_e0f2_709b_4eff_fdea32177425 f0e5b8dc_281e_050f_2de0_2838969a600b["onFileChange()"] f0e5b8dc_281e_050f_2de0_2838969a600b -->|calls| 9eb17063_e0f2_709b_4eff_fdea32177425 8cb1b522_2bee_f4c7_3c23_952c0f3b82d2["invalidateAll()"] 8cb1b522_2bee_f4c7_3c23_952c0f3b82d2 -->|calls| 9eb17063_e0f2_709b_4eff_fdea32177425 f64686c5_88e2_949b_57b5_197f77dea3a7["updateModules()"] f64686c5_88e2_949b_57b5_197f77dea3a7 -->|calls| 9eb17063_e0f2_709b_4eff_fdea32177425 74ee9886_2456_3964_e90e_5fc67925229d["monotonicDateNow()"] 9eb17063_e0f2_709b_4eff_fdea32177425 -->|calls| 74ee9886_2456_3964_e90e_5fc67925229d style 9eb17063_e0f2_709b_4eff_fdea32177425 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/server/moduleGraph.ts lines 166–234
invalidateModule(
mod: EnvironmentModuleNode,
seen: Set<EnvironmentModuleNode> = new Set(),
timestamp: number = monotonicDateNow(),
isHmr: boolean = false,
/** @internal */
softInvalidate = false,
): void {
const prevInvalidationState = mod.invalidationState
// Handle soft invalidation before the `seen` check, as consecutive soft/hard invalidations can
// cause the final soft invalidation state to be different.
// If soft invalidated, save the previous `transformResult` so that we can reuse and transform the
// import timestamps only in `transformRequest`. If there's no previous `transformResult`, hard invalidate it.
if (softInvalidate) {
mod.invalidationState ??= mod.transformResult ?? 'HARD_INVALIDATED'
}
// If hard invalidated, further soft invalidations have no effect until it's reset to `undefined`
else {
mod.invalidationState = 'HARD_INVALIDATED'
}
// Skip updating the module if it was already invalidated before and the invalidation state has not changed
if (seen.has(mod) && prevInvalidationState === mod.invalidationState) {
return
}
seen.add(mod)
if (isHmr) {
mod.lastHMRTimestamp = timestamp
mod.lastHMRInvalidationReceived = false
} else {
// Save the timestamp for this invalidation, so we can avoid caching the result of possible already started
// processing being done for this module
mod.lastInvalidationTimestamp = timestamp
}
// Don't invalidate mod.info and mod.meta, as they are part of the processing pipeline
// Invalidating the transform result is enough to ensure this module is re-processed next time it is requested
const etag = mod.transformResult?.etag
if (etag) this.etagToModuleMap.delete(etag)
mod.transformResult = null
mod.ssrModule = null
mod.ssrError = null
mod.importers.forEach((importer) => {
if (!importer.acceptedHmrDeps.has(mod)) {
// If the importer statically imports the current module, we can soft-invalidate the importer
// to only update the import timestamps. If it's not statically imported, e.g. watched/glob file,
// we can only soft invalidate if the current module was also soft-invalidated. A soft-invalidation
// doesn't need to trigger a re-load and re-transform of the importer.
// But we exclude direct CSS files as those cannot be soft invalidated.
const shouldSoftInvalidateImporter =
(importer.staticImportedUrls?.has(mod.url) || softInvalidate) &&
importer.type === 'js'
this.invalidateModule(
importer,
seen,
timestamp,
isHmr,
shouldSoftInvalidateImporter,
)
}
})
this._hasResolveFailedErrorModules.delete(mod)
}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does invalidateModule() do?
invalidateModule() is a function in the vite codebase, defined in packages/vite/src/node/server/moduleGraph.ts.
Where is invalidateModule() defined?
invalidateModule() is defined in packages/vite/src/node/server/moduleGraph.ts at line 166.
What does invalidateModule() call?
invalidateModule() calls 1 function(s): monotonicDateNow.
What calls invalidateModule()?
invalidateModule() is called by 5 function(s): invalidateAll, invalidateModule, invalidateModule, onFileChange, updateModules.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free