Skip to content

Commit

Permalink
fix: backport outdated optimized dep removed from module graph (#8534)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jun 10, 2022
1 parent 078a7dc commit c0d6c60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Expand Up @@ -50,7 +50,10 @@ import {
optimizedDepNeedsInterop
} from '../optimizer'
import { checkPublicFile } from './asset'
import { ERR_OUTDATED_OPTIMIZED_DEP } from './optimizedDeps'
import {
ERR_OUTDATED_OPTIMIZED_DEP,
throwOutdatedRequest
} from './optimizedDeps'
import { isCSSRequest, isDirectCSSRequest } from './css'

const isDebug = !!process.env.DEBUG
Expand Down Expand Up @@ -170,6 +173,13 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
// since we are already in the transform phase of the importer, it must
// have been loaded so its entry is guaranteed in the module graph.
const importerModule = moduleGraph.getModuleById(importer)!
if (!importerModule && isOptimizedDepFile(importer, config)) {
// Ids of optimized deps could be invalidated and removed from the graph
// Return without transforming, this request is no longer valid, a full reload
// is going to request this id again. Throwing an outdated error so we
// properly finish the request with a 504 sent to the browser.
throwOutdatedRequest(importer)
}

if (!imports.length) {
importerModule.isSelfAccepting = false
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/optimizedDeps.ts
Expand Up @@ -73,7 +73,7 @@ export function optimizedDepsPlugin(): Plugin {
}
}

function throwProcessingError(id: string) {
function throwProcessingError(id: string): never {
const err: any = new Error(
`Something unexpected happened while optimizing "${id}". ` +
`The current page should have reloaded by now`
Expand All @@ -84,7 +84,7 @@ function throwProcessingError(id: string) {
throw err
}

function throwOutdatedRequest(id: string) {
export function throwOutdatedRequest(id: string): never {
const err: any = new Error(
`There is a new version of the pre-bundle for "${id}", ` +
`a page reload is going to ask for it.`
Expand Down

0 comments on commit c0d6c60

Please sign in to comment.