File tree 2 files changed +13
-3
lines changed
packages/vite/src/node/plugins
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,10 @@ import {
50
50
optimizedDepNeedsInterop
51
51
} from '../optimizer'
52
52
import { checkPublicFile } from './asset'
53
- import { ERR_OUTDATED_OPTIMIZED_DEP } from './optimizedDeps'
53
+ import {
54
+ ERR_OUTDATED_OPTIMIZED_DEP ,
55
+ throwOutdatedRequest
56
+ } from './optimizedDeps'
54
57
import { isCSSRequest , isDirectCSSRequest } from './css'
55
58
56
59
const isDebug = ! ! process . env . DEBUG
@@ -170,6 +173,13 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
170
173
// since we are already in the transform phase of the importer, it must
171
174
// have been loaded so its entry is guaranteed in the module graph.
172
175
const importerModule = moduleGraph . getModuleById ( importer ) !
176
+ if ( ! importerModule && isOptimizedDepFile ( importer , config ) ) {
177
+ // Ids of optimized deps could be invalidated and removed from the graph
178
+ // Return without transforming, this request is no longer valid, a full reload
179
+ // is going to request this id again. Throwing an outdated error so we
180
+ // properly finish the request with a 504 sent to the browser.
181
+ throwOutdatedRequest ( importer )
182
+ }
173
183
174
184
if ( ! imports . length ) {
175
185
importerModule . isSelfAccepting = false
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ export function optimizedDepsPlugin(): Plugin {
73
73
}
74
74
}
75
75
76
- function throwProcessingError ( id : string ) {
76
+ function throwProcessingError ( id : string ) : never {
77
77
const err : any = new Error (
78
78
`Something unexpected happened while optimizing "${ id } ". ` +
79
79
`The current page should have reloaded by now`
@@ -84,7 +84,7 @@ function throwProcessingError(id: string) {
84
84
throw err
85
85
}
86
86
87
- function throwOutdatedRequest ( id : string ) {
87
+ export function throwOutdatedRequest ( id : string ) : never {
88
88
const err : any = new Error (
89
89
`There is a new version of the pre-bundle for "${ id } ", ` +
90
90
`a page reload is going to ask for it.`
You can’t perform that action at this time.
0 commit comments