@@ -250,11 +250,6 @@ export async function* serveWithVite(
250
250
) ;
251
251
}
252
252
253
- // Invalidate SSR module graph to ensure that only new rebuild is used and not stale component updates
254
- if ( server && browserOptions . ssr && templateUpdates . size > 0 ) {
255
- server . moduleGraph . invalidateAll ( ) ;
256
- }
257
-
258
253
// Clear stale template updates on code rebuilds
259
254
templateUpdates . clear ( ) ;
260
255
@@ -302,17 +297,6 @@ export async function* serveWithVite(
302
297
server ,
303
298
'Builder must provide an initial full build before component update results.' ,
304
299
) ;
305
-
306
- // Invalidate SSR module graph to ensure that new component updates are used
307
- // TODO: Use fine-grained invalidation of only the component update modules
308
- if ( browserOptions . ssr ) {
309
- server . moduleGraph . invalidateAll ( ) ;
310
- const { ɵresetCompiledComponents } = ( await server . ssrLoadModule ( '/main.server.mjs' ) ) as {
311
- ɵresetCompiledComponents : ( ) => void ;
312
- } ;
313
- ɵresetCompiledComponents ( ) ;
314
- }
315
-
316
300
for ( const componentUpdate of result . updates ) {
317
301
if ( componentUpdate . type === 'template' ) {
318
302
templateUpdates . set ( componentUpdate . id , componentUpdate . content ) ;
@@ -367,16 +351,15 @@ export async function* serveWithVite(
367
351
] ) ,
368
352
] ;
369
353
354
+ const updatedFiles = await invalidateUpdatedFiles (
355
+ normalizePath ,
356
+ generatedFiles ,
357
+ assetFiles ,
358
+ server ,
359
+ ) ;
360
+
370
361
if ( needClientUpdate ) {
371
- await handleUpdate (
372
- normalizePath ,
373
- generatedFiles ,
374
- assetFiles ,
375
- server ,
376
- serverOptions ,
377
- context . logger ,
378
- componentStyles ,
379
- ) ;
362
+ handleUpdate ( server , serverOptions , context . logger , componentStyles , updatedFiles ) ;
380
363
}
381
364
} else {
382
365
const projectName = context . target ?. project ;
@@ -483,16 +466,20 @@ export async function* serveWithVite(
483
466
await new Promise < void > ( ( resolve ) => ( deferred = resolve ) ) ;
484
467
}
485
468
486
- async function handleUpdate (
469
+ /**
470
+ * Invalidates any updated asset or generated files and resets their `updated` state.
471
+ * This function also clears the server application cache when necessary.
472
+ *
473
+ * @returns A list of files that were updated and invalidated.
474
+ */
475
+ async function invalidateUpdatedFiles (
487
476
normalizePath : ( id : string ) => string ,
488
477
generatedFiles : Map < string , OutputFileRecord > ,
489
478
assetFiles : Map < string , OutputAssetRecord > ,
490
479
server : ViteDevServer ,
491
- serverOptions : NormalizedDevServerOptions ,
492
- logger : BuilderContext [ 'logger' ] ,
493
- componentStyles : Map < string , ComponentStyleRecord > ,
494
- ) : Promise < void > {
480
+ ) : Promise < string [ ] > {
495
481
const updatedFiles : string [ ] = [ ] ;
482
+ let destroyAngularServerAppCalled = false ;
496
483
497
484
// Invalidate any updated asset
498
485
for ( const [ file , record ] of assetFiles ) {
@@ -505,7 +492,6 @@ async function handleUpdate(
505
492
}
506
493
507
494
// Invalidate any updated files
508
- let destroyAngularServerAppCalled = false ;
509
495
for ( const [ file , record ] of generatedFiles ) {
510
496
if ( ! record . updated ) {
511
497
continue ;
@@ -531,15 +517,25 @@ async function handleUpdate(
531
517
updatedModules ?. forEach ( ( m ) => server . moduleGraph . invalidateModule ( m ) ) ;
532
518
}
533
519
520
+ return updatedFiles ;
521
+ }
522
+
523
+ /**
524
+ * Handles updates for the client by sending HMR or full page reload commands
525
+ * based on the updated files. It also ensures proper tracking of component styles and determines if
526
+ * a full reload is needed.
527
+ */
528
+ function handleUpdate (
529
+ server : ViteDevServer ,
530
+ serverOptions : NormalizedDevServerOptions ,
531
+ logger : BuilderContext [ 'logger' ] ,
532
+ componentStyles : Map < string , ComponentStyleRecord > ,
533
+ updatedFiles : string [ ] ,
534
+ ) : void {
534
535
if ( ! updatedFiles . length ) {
535
536
return ;
536
537
}
537
538
538
- if ( destroyAngularServerAppCalled ) {
539
- // Trigger module evaluation before reload to initiate dependency optimization.
540
- await server . ssrLoadModule ( '/main.server.mjs' ) ;
541
- }
542
-
543
539
if ( serverOptions . hmr ) {
544
540
if ( updatedFiles . every ( ( f ) => f . endsWith ( '.css' ) ) ) {
545
541
let requiresReload = false ;
0 commit comments