@@ -97,13 +97,17 @@ export class HMRContext implements ViteHotContext {
97
97
decline ( ) : void { }
98
98
99
99
invalidate ( message : string ) : void {
100
+ const firstInvalidatedBy =
101
+ this . hmrClient . currentFirstInvalidatedBy ?? this . ownerPath
100
102
this . hmrClient . notifyListeners ( 'vite:invalidate' , {
101
103
path : this . ownerPath ,
102
104
message,
105
+ firstInvalidatedBy,
103
106
} )
104
107
this . send ( 'vite:invalidate' , {
105
108
path : this . ownerPath ,
106
109
message,
110
+ firstInvalidatedBy,
107
111
} )
108
112
this . hmrClient . logger . debug (
109
113
`invalidate ${ this . ownerPath } ${ message ? `: ${ message } ` : '' } ` ,
@@ -170,6 +174,7 @@ export class HMRClient {
170
174
public dataMap = new Map < string , any > ( )
171
175
public customListenersMap : CustomListenersMap = new Map ( )
172
176
public ctxToListenersMap = new Map < string , CustomListenersMap > ( )
177
+ public currentFirstInvalidatedBy : string | undefined
173
178
174
179
constructor (
175
180
public logger : HMRLogger ,
@@ -254,7 +259,7 @@ export class HMRClient {
254
259
}
255
260
256
261
private async fetchUpdate ( update : Update ) : Promise < ( ( ) => void ) | undefined > {
257
- const { path, acceptedPath } = update
262
+ const { path, acceptedPath, firstInvalidatedBy } = update
258
263
const mod = this . hotModulesMap . get ( path )
259
264
if ( ! mod ) {
260
265
// In a code-splitting project,
@@ -282,13 +287,20 @@ export class HMRClient {
282
287
}
283
288
284
289
return ( ) => {
285
- for ( const { deps, fn } of qualifiedCallbacks ) {
286
- fn (
287
- deps . map ( ( dep ) => ( dep === acceptedPath ? fetchedModule : undefined ) ) ,
288
- )
290
+ try {
291
+ this . currentFirstInvalidatedBy = firstInvalidatedBy
292
+ for ( const { deps, fn } of qualifiedCallbacks ) {
293
+ fn (
294
+ deps . map ( ( dep ) =>
295
+ dep === acceptedPath ? fetchedModule : undefined ,
296
+ ) ,
297
+ )
298
+ }
299
+ const loggedPath = isSelfUpdate ? path : `${ acceptedPath } via ${ path } `
300
+ this . logger . debug ( `hot updated: ${ loggedPath } ` )
301
+ } finally {
302
+ this . currentFirstInvalidatedBy = undefined
289
303
}
290
- const loggedPath = isSelfUpdate ? path : `${ acceptedPath } via ${ path } `
291
- this . logger . debug ( `hot updated: ${ loggedPath } ` )
292
304
}
293
305
}
294
306
}
0 commit comments