@@ -225,6 +225,15 @@ export async function* serveWithVite(
225
225
} ) ;
226
226
}
227
227
228
+ if ( browserOptions . ssr && server ) {
229
+ // Clean up all Angular cached component IDs on every change.
230
+ // This is the same thing that happens on the client (browser refresh).
231
+ const { ɵresetCompiledComponents } = ( await server . ssrLoadModule ( '/main.server.mjs' ) ) as {
232
+ ɵresetCompiledComponents : ( ) => void ;
233
+ } ;
234
+ ɵresetCompiledComponents ( ) ;
235
+ }
236
+
228
237
let needClientUpdate = true ;
229
238
switch ( result . kind ) {
230
239
case ResultKind . Full :
@@ -501,24 +510,13 @@ async function invalidateUpdatedFiles(
501
510
}
502
511
503
512
// Invalidate any updated files
504
- let destroyAngularServerAppCalled = false ;
513
+ let callDestroyAngularServerApp = false ;
505
514
for ( const [ file , record ] of generatedFiles ) {
506
515
if ( ! record . updated ) {
507
516
continue ;
508
517
}
509
518
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
- }
521
-
519
+ callDestroyAngularServerApp ||= record . type === BuildOutputFileType . ServerApplication ;
522
520
updatedFiles . push ( file ) ;
523
521
524
522
const updatedModules = server . moduleGraph . getModulesByFile (
@@ -527,9 +525,14 @@ async function invalidateUpdatedFiles(
527
525
updatedModules ?. forEach ( ( m ) => server . moduleGraph . invalidateModule ( m ) ) ;
528
526
}
529
527
530
- if ( destroyAngularServerAppCalled ) {
531
- // Trigger module evaluation before reload to initiate dependency optimization.
532
- await server . ssrLoadModule ( '/main.server.mjs' ) ;
528
+ // Trigger module evaluation before reload to initiate dependency optimization.
529
+ // and clear Angular Component IDs
530
+ if ( callDestroyAngularServerApp ) {
531
+ const { ɵdestroyAngularServerApp } = ( await server . ssrLoadModule ( '/main.server.mjs' ) ) as {
532
+ ɵdestroyAngularServerApp : typeof destroyAngularServerApp ;
533
+ } ;
534
+
535
+ ɵdestroyAngularServerApp ( ) ;
533
536
}
534
537
535
538
return updatedFiles ;
0 commit comments