@@ -301,19 +301,8 @@ export class Application implements ServerApplication {
301301 log . info ( type , url )
302302 try {
303303 const module = await this . initModule ( url , { forceRefresh : true } )
304+ const hmrable = this . isHMRable ( url )
304305 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- }
317306 if ( hmrable ) {
318307 let routePath : string | undefined = undefined
319308 let withData : boolean | undefined = undefined
@@ -340,10 +329,9 @@ export class Application implements ServerApplication {
340329 } )
341330 }
342331 }
343- updateRouting ( module . url )
344332 this . applyCompilationSideEffect ( module , ( { url : effectUrl } ) => {
345- updateRouting ( effectUrl )
346333 if ( ! hmrable && this . isHMRable ( effectUrl ) ) {
334+ log . debug ( 'compilation side-effect:' , effectUrl , dim ( '<-' ) , module . url )
347335 this . #fsWatchListeners. forEach ( w => w . emit ( 'modify-' + effectUrl ) )
348336 }
349337 } )
@@ -1210,6 +1198,7 @@ export class Application implements ServerApplication {
12101198 private async applyCompilationSideEffect ( by : Module , callback : ( mod : Module ) => void ) {
12111199 const hash = by . hash || by . sourceHash
12121200 const hashData = ( new TextEncoder ( ) ) . encode ( hash . substr ( 0 , 6 ) )
1201+ this . applyModuleSideEffect ( by . url )
12131202 for ( const mod of this . #modules. values ( ) ) {
12141203 const { deps } = mod
12151204 if ( deps . length > 0 ) {
@@ -1228,7 +1217,6 @@ export class Application implements ServerApplication {
12281217 }
12291218 }
12301219 if ( fsync ) {
1231- log . debug ( 'compilation side-effect:' , mod . url , dim ( '<-' ) , by . url )
12321220 const hasher = createHash ( 'md5' ) . update ( mod . sourceHash )
12331221 deps . forEach ( ( { url } ) => {
12341222 const depMod = url === by . url ? by : this . #modules. get ( url )
@@ -1238,13 +1226,26 @@ export class Application implements ServerApplication {
12381226 } )
12391227 mod . hash = hasher . toString ( )
12401228 await this . cacheModule ( mod )
1229+ this . applyModuleSideEffect ( mod . url )
12411230 callback ( mod )
12421231 await this . applyCompilationSideEffect ( mod , callback )
12431232 }
12441233 }
12451234 }
12461235 }
12471236
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+
12481249 private async cacheModule ( module : Module ) {
12491250 const { url, jsCode, jsFile } = module
12501251 if ( jsCode ) {
0 commit comments