Skip to content
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: backport outdated optimized dep removed from module graph #8534

Merged
merged 1 commit into from Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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