@@ -501,35 +501,30 @@ async function invalidateUpdatedFiles(
501501 }
502502
503503 // Invalidate any updated files
504- let destroyAngularServerAppCalled = false ;
504+ let serverApplicationChanged = false ;
505505 for ( const [ file , record ] of generatedFiles ) {
506506 if ( ! record . updated ) {
507507 continue ;
508508 }
509- record . updated = false ;
510-
511- if ( record . type === BuildOutputFileType . ServerApplication && ! destroyAngularServerAppCalled ) {
512- // Clear the server app cache
513- // This must be done before module invalidation.
514- const { ɵdestroyAngularServerApp } = ( await server . ssrLoadModule ( '/main.server.mjs' ) ) as {
515- ɵdestroyAngularServerApp : typeof destroyAngularServerApp ;
516- } ;
517-
518- ɵdestroyAngularServerApp ( ) ;
519- destroyAngularServerAppCalled = true ;
520- }
521509
510+ record . updated = false ;
522511 updatedFiles . push ( file ) ;
512+ serverApplicationChanged ||= record . type === BuildOutputFileType . ServerApplication ;
523513
524514 const updatedModules = server . moduleGraph . getModulesByFile (
525515 normalizePath ( join ( server . config . root , file ) ) ,
526516 ) ;
527517 updatedModules ?. forEach ( ( m ) => server . moduleGraph . invalidateModule ( m ) ) ;
528518 }
529519
530- if ( destroyAngularServerAppCalled ) {
531- // Trigger module evaluation before reload to initiate dependency optimization.
532- await server . ssrLoadModule ( '/main.server.mjs' ) ;
520+ if ( serverApplicationChanged ) {
521+ // Clear the server app cache and
522+ // trigger module evaluation before reload to initiate dependency optimization.
523+ const { ɵdestroyAngularServerApp } = ( await server . ssrLoadModule ( '/main.server.mjs' ) ) as {
524+ ɵdestroyAngularServerApp : typeof destroyAngularServerApp ;
525+ } ;
526+
527+ ɵdestroyAngularServerApp ( ) ;
533528 }
534529
535530 return updatedFiles ;
0 commit comments