@@ -301,19 +301,8 @@ export class Application implements ServerApplication {
301
301
log . info ( type , url )
302
302
try {
303
303
const module = await this . initModule ( url , { forceRefresh : true } )
304
+ const hmrable = this . isHMRable ( url )
304
305
await this . transpileModule ( module , true )
305
- const hmrable = this . isHMRable ( module . url )
306
- const updateRouting = ( url : string ) => {
307
- if ( trimModuleExt ( url ) === '/app' ) {
308
- this . #renderer. clearCache ( )
309
- } else if ( url . startsWith ( '/pages/' ) ) {
310
- const [ routePath ] = this . createRouteUpdate ( url )
311
- this . #renderer. clearCache ( routePath )
312
- this . #pageRouting. update ( ...this . createRouteUpdate ( url ) )
313
- } else if ( url . startsWith ( '/api/' ) ) {
314
- this . #apiRouting. update ( ...this . createRouteUpdate ( url ) )
315
- }
316
- }
317
306
if ( hmrable ) {
318
307
let routePath : string | undefined = undefined
319
308
let withData : boolean | undefined = undefined
@@ -340,10 +329,9 @@ export class Application implements ServerApplication {
340
329
} )
341
330
}
342
331
}
343
- updateRouting ( module . url )
344
332
this . applyCompilationSideEffect ( module , ( { url : effectUrl } ) => {
345
- updateRouting ( effectUrl )
346
333
if ( ! hmrable && this . isHMRable ( effectUrl ) ) {
334
+ log . debug ( 'compilation side-effect:' , effectUrl , dim ( '<-' ) , module . url )
347
335
this . #fsWatchListeners. forEach ( w => w . emit ( 'modify-' + effectUrl ) )
348
336
}
349
337
} )
@@ -1210,6 +1198,7 @@ export class Application implements ServerApplication {
1210
1198
private async applyCompilationSideEffect ( by : Module , callback : ( mod : Module ) => void ) {
1211
1199
const hash = by . hash || by . sourceHash
1212
1200
const hashData = ( new TextEncoder ( ) ) . encode ( hash . substr ( 0 , 6 ) )
1201
+ this . applyModuleSideEffect ( by . url )
1213
1202
for ( const mod of this . #modules. values ( ) ) {
1214
1203
const { deps } = mod
1215
1204
if ( deps . length > 0 ) {
@@ -1228,7 +1217,6 @@ export class Application implements ServerApplication {
1228
1217
}
1229
1218
}
1230
1219
if ( fsync ) {
1231
- log . debug ( 'compilation side-effect:' , mod . url , dim ( '<-' ) , by . url )
1232
1220
const hasher = createHash ( 'md5' ) . update ( mod . sourceHash )
1233
1221
deps . forEach ( ( { url } ) => {
1234
1222
const depMod = url === by . url ? by : this . #modules. get ( url )
@@ -1238,13 +1226,26 @@ export class Application implements ServerApplication {
1238
1226
} )
1239
1227
mod . hash = hasher . toString ( )
1240
1228
await this . cacheModule ( mod )
1229
+ this . applyModuleSideEffect ( mod . url )
1241
1230
callback ( mod )
1242
1231
await this . applyCompilationSideEffect ( mod , callback )
1243
1232
}
1244
1233
}
1245
1234
}
1246
1235
}
1247
1236
1237
+ private applyModuleSideEffect ( url : string ) {
1238
+ if ( trimModuleExt ( url ) === '/app' ) {
1239
+ this . #renderer. clearCache ( )
1240
+ } else if ( url . startsWith ( '/pages/' ) ) {
1241
+ const [ routePath ] = this . createRouteUpdate ( url )
1242
+ this . #renderer. clearCache ( routePath )
1243
+ this . #pageRouting. update ( ...this . createRouteUpdate ( url ) )
1244
+ } else if ( url . startsWith ( '/api/' ) ) {
1245
+ this . #apiRouting. update ( ...this . createRouteUpdate ( url ) )
1246
+ }
1247
+ }
1248
+
1248
1249
private async cacheModule ( module : Module ) {
1249
1250
const { url, jsCode, jsFile } = module
1250
1251
if ( jsCode ) {
0 commit comments