File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
packages/vite/src/node/plugins Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,10 @@ import {
5050 optimizedDepNeedsInterop
5151} from '../optimizer'
5252import { checkPublicFile } from './asset'
53- import { ERR_OUTDATED_OPTIMIZED_DEP } from './optimizedDeps'
53+ import {
54+ ERR_OUTDATED_OPTIMIZED_DEP ,
55+ throwOutdatedRequest
56+ } from './optimizedDeps'
5457import { isCSSRequest , isDirectCSSRequest } from './css'
5558
5659const isDebug = ! ! process . env . DEBUG
@@ -170,6 +173,13 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
170173 // since we are already in the transform phase of the importer, it must
171174 // have been loaded so its entry is guaranteed in the module graph.
172175 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+ }
173183
174184 if ( ! imports . length ) {
175185 importerModule . isSelfAccepting = false
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ export function optimizedDepsPlugin(): Plugin {
7373 }
7474}
7575
76- function throwProcessingError ( id : string ) {
76+ function throwProcessingError ( id : string ) : never {
7777 const err : any = new Error (
7878 `Something unexpected happened while optimizing "${ id } ". ` +
7979 `The current page should have reloaded by now`
@@ -84,7 +84,7 @@ function throwProcessingError(id: string) {
8484 throw err
8585}
8686
87- function throwOutdatedRequest ( id : string ) {
87+ export function throwOutdatedRequest ( id : string ) : never {
8888 const err : any = new Error (
8989 `There is a new version of the pre-bundle for "${ id } ", ` +
9090 `a page reload is going to ask for it.`
You can’t perform that action at this time.
0 commit comments