@@ -218,6 +218,8 @@ export async function* serveWithVite(
218
218
}
219
219
220
220
let needClientUpdate = true ;
221
+ const componentUpdateIds : string [ ] = [ ] ;
222
+
221
223
switch ( result . kind ) {
222
224
case ResultKind . Full :
223
225
if ( result . detail ?. [ 'htmlIndexPath' ] ) {
@@ -250,11 +252,6 @@ export async function* serveWithVite(
250
252
) ;
251
253
}
252
254
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
255
// Clear stale template updates on code rebuilds
259
256
templateUpdates . clear ( ) ;
260
257
@@ -302,28 +299,14 @@ export async function* serveWithVite(
302
299
server ,
303
300
'Builder must provide an initial full build before component update results.' ,
304
301
) ;
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
302
for ( const componentUpdate of result . updates ) {
317
303
if ( componentUpdate . type === 'template' ) {
304
+ componentUpdateIds . push ( componentUpdate . id ) ;
318
305
templateUpdates . set ( componentUpdate . id , componentUpdate . content ) ;
319
- server . ws . send ( 'angular:component-update' , {
320
- id : componentUpdate . id ,
321
- timestamp : Date . now ( ) ,
322
- } ) ;
323
306
}
324
307
}
325
- context . logger . info ( 'Component update sent to client(s).' ) ;
326
- continue ;
308
+
309
+ break ;
327
310
default :
328
311
context . logger . warn ( `Unknown result kind [${ ( result as Result ) . kind } ] provided by build.` ) ;
329
312
continue ;
@@ -367,17 +350,17 @@ export async function* serveWithVite(
367
350
] ) ,
368
351
] ;
369
352
370
- if ( needClientUpdate ) {
371
- await handleUpdate (
372
- normalizePath ,
373
- generatedFiles ,
374
- assetFiles ,
375
- server ,
376
- serverOptions ,
377
- context . logger ,
378
- componentStyles ,
379
- ) ;
380
- }
353
+ await handleUpdate (
354
+ normalizePath ,
355
+ generatedFiles ,
356
+ assetFiles ,
357
+ server ,
358
+ serverOptions ,
359
+ context . logger ,
360
+ componentStyles ,
361
+ componentUpdateIds ,
362
+ needClientUpdate ,
363
+ ) ;
381
364
} else {
382
365
const projectName = context . target ?. project ;
383
366
if ( ! projectName ) {
@@ -491,6 +474,8 @@ async function handleUpdate(
491
474
serverOptions : NormalizedDevServerOptions ,
492
475
logger : BuilderContext [ 'logger' ] ,
493
476
componentStyles : Map < string , ComponentStyleRecord > ,
477
+ componentUpdateIds : string [ ] ,
478
+ needClientUpdate : boolean ,
494
479
) : Promise < void > {
495
480
const updatedFiles : string [ ] = [ ] ;
496
481
@@ -531,7 +516,11 @@ async function handleUpdate(
531
516
updatedModules ?. forEach ( ( m ) => server . moduleGraph . invalidateModule ( m ) ) ;
532
517
}
533
518
534
- if ( ! updatedFiles . length ) {
519
+ if ( ! needClientUpdate ) {
520
+ return ;
521
+ }
522
+
523
+ if ( ! updatedFiles . length && ! componentUpdateIds . length ) {
535
524
return ;
536
525
}
537
526
@@ -541,6 +530,17 @@ async function handleUpdate(
541
530
}
542
531
543
532
if ( serverOptions . hmr ) {
533
+ for ( const id of componentUpdateIds ) {
534
+ server . ws . send ( 'angular:component-update' , {
535
+ id,
536
+ timestamp : Date . now ( ) ,
537
+ } ) ;
538
+ }
539
+
540
+ if ( componentUpdateIds . length ) {
541
+ logger . info ( 'Component update sent to client(s).' ) ;
542
+ }
543
+
544
544
if ( updatedFiles . every ( ( f ) => f . endsWith ( '.css' ) ) ) {
545
545
let requiresReload = false ;
546
546
const timestamp = Date . now ( ) ;
0 commit comments