@@ -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
@@ -303,16 +298,6 @@ export async function* serveWithVite(
303
298
'Builder must provide an initial full build before component update results.' ,
304
299
) ;
305
300
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
301
for ( const componentUpdate of result . updates ) {
317
302
if ( componentUpdate . type === 'template' ) {
318
303
templateUpdates . set ( componentUpdate . id , componentUpdate . content ) ;
@@ -322,6 +307,7 @@ export async function* serveWithVite(
322
307
} ) ;
323
308
}
324
309
}
310
+
325
311
context . logger . info ( 'Component update sent to client(s).' ) ;
326
312
continue ;
327
313
default :
@@ -367,16 +353,15 @@ export async function* serveWithVite(
367
353
] ) ,
368
354
] ;
369
355
356
+ const updatedFiles = await invalidateUpdatedFiles (
357
+ normalizePath ,
358
+ generatedFiles ,
359
+ assetFiles ,
360
+ server ,
361
+ ) ;
362
+
370
363
if ( needClientUpdate ) {
371
- await handleUpdate (
372
- normalizePath ,
373
- generatedFiles ,
374
- assetFiles ,
375
- server ,
376
- serverOptions ,
377
- context . logger ,
378
- componentStyles ,
379
- ) ;
364
+ handleUpdate ( server , serverOptions , context . logger , componentStyles , updatedFiles ) ;
380
365
}
381
366
} else {
382
367
const projectName = context . target ?. project ;
@@ -483,15 +468,18 @@ export async function* serveWithVite(
483
468
await new Promise < void > ( ( resolve ) => ( deferred = resolve ) ) ;
484
469
}
485
470
486
- async function handleUpdate (
471
+ /**
472
+ * Invalidates any updated asset or generated files and resets their `updated` state.
473
+ * This function also clears the server application cache when necessary.
474
+ *
475
+ * @returns A list of files that were updated and invalidated.
476
+ */
477
+ async function invalidateUpdatedFiles (
487
478
normalizePath : ( id : string ) => string ,
488
479
generatedFiles : Map < string , OutputFileRecord > ,
489
480
assetFiles : Map < string , OutputAssetRecord > ,
490
481
server : ViteDevServer ,
491
- serverOptions : NormalizedDevServerOptions ,
492
- logger : BuilderContext [ 'logger' ] ,
493
- componentStyles : Map < string , ComponentStyleRecord > ,
494
- ) : Promise < void > {
482
+ ) : Promise < string [ ] > {
495
483
const updatedFiles : string [ ] = [ ] ;
496
484
497
485
// Invalidate any updated asset
@@ -531,15 +519,30 @@ async function handleUpdate(
531
519
updatedModules ?. forEach ( ( m ) => server . moduleGraph . invalidateModule ( m ) ) ;
532
520
}
533
521
534
- if ( ! updatedFiles . length ) {
535
- return ;
536
- }
537
-
538
522
if ( destroyAngularServerAppCalled ) {
539
523
// Trigger module evaluation before reload to initiate dependency optimization.
540
524
await server . ssrLoadModule ( '/main.server.mjs' ) ;
541
525
}
542
526
527
+ return updatedFiles ;
528
+ }
529
+
530
+ /**
531
+ * Handles updates for the client by sending HMR or full page reload commands
532
+ * based on the updated files. It also ensures proper tracking of component styles and determines if
533
+ * a full reload is needed.
534
+ */
535
+ function handleUpdate (
536
+ server : ViteDevServer ,
537
+ serverOptions : NormalizedDevServerOptions ,
538
+ logger : BuilderContext [ 'logger' ] ,
539
+ componentStyles : Map < string , ComponentStyleRecord > ,
540
+ updatedFiles : string [ ] ,
541
+ ) : void {
542
+ if ( ! updatedFiles . length ) {
543
+ return ;
544
+ }
545
+
543
546
if ( serverOptions . hmr ) {
544
547
if ( updatedFiles . every ( ( f ) => f . endsWith ( '.css' ) ) ) {
545
548
let requiresReload = false ;
0 commit comments