File tree 6 files changed +33
-0
lines changed
6 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -311,6 +311,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
311
311
}
312
312
// fix#9534, prevent the importerModuleNode being stopped from propagating updates
313
313
importerModule . isSelfAccepting = false
314
+ moduleGraph . _hasResolveFailedErrorModules . add ( importerModule )
314
315
return this . error (
315
316
`Failed to resolve import "${ url } " from "${ normalizePath (
316
317
path . relative ( process . cwd ( ) , importerFile ) ,
Original file line number Diff line number Diff line change @@ -163,6 +163,11 @@ export async function handleHMRUpdate(
163
163
}
164
164
165
165
const mods = new Set ( moduleGraph . getModulesByFile ( file ) )
166
+ if ( type === 'create' ) {
167
+ for ( const mod of moduleGraph . _hasResolveFailedErrorModules ) {
168
+ mods . add ( mod )
169
+ }
170
+ }
166
171
if ( type === 'create' || type === 'delete' ) {
167
172
for ( const mod of getAffectedGlobModules ( file , server ) ) {
168
173
mods . add ( mod )
Original file line number Diff line number Diff line change @@ -108,6 +108,9 @@ export class ModuleGraph {
108
108
Promise < ModuleNode > | ModuleNode
109
109
> ( )
110
110
111
+ /** @internal */
112
+ _hasResolveFailedErrorModules = new Set < ModuleNode > ( )
113
+
111
114
constructor (
112
115
private resolveId : (
113
116
url : string ,
@@ -229,6 +232,8 @@ export class ModuleGraph {
229
232
)
230
233
}
231
234
} )
235
+
236
+ this . _hasResolveFailedErrorModules . delete ( mod )
232
237
}
233
238
234
239
invalidateAll ( ) : void {
Original file line number Diff line number Diff line change @@ -962,4 +962,23 @@ if (!isBuild) {
962
962
editFile ( 'css-deps/dep.js' , ( code ) => code . replace ( `red` , `green` ) )
963
963
await untilUpdated ( ( ) => getColor ( '.css-deps' ) , 'green' )
964
964
} )
965
+
966
+ test ( 'hmr should happen after missing file is created' , async ( ) => {
967
+ const file = 'missing-file/a.js'
968
+ const code = 'console.log("a.js")'
969
+
970
+ await untilBrowserLogAfter (
971
+ ( ) =>
972
+ page . goto ( viteTestUrl + '/missing-file/index.html' , {
973
+ waitUntil : 'load' ,
974
+ } ) ,
975
+ / c o n n e c t e d / , // wait for HMR connection
976
+ )
977
+
978
+ await untilBrowserLogAfter ( async ( ) => {
979
+ const loadPromise = page . waitForEvent ( 'load' )
980
+ addFile ( file , code )
981
+ await loadPromise
982
+ } , [ / c o n n e c t e d / , 'a.js' ] )
983
+ } )
965
984
}
Original file line number Diff line number Diff line change
1
+ < div > Page</ div >
2
+ < script type ="module " src ="main.js "> </ script >
Original file line number Diff line number Diff line change
1
+ import './a.js'
You can’t perform that action at this time.
0 commit comments