From 3ce5e588f5d590b00ef86bb0dd5837f148071554 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 23 Sep 2024 08:12:42 +0000 Subject: [PATCH] feat(@schematics/angular): integrate `withEventReplay()` in `provideClientHydration` for new SSR apps Event Replay is now stable (see https://github.com/angular/angular/pull/57895). This commit adds `withEventReplay()` to the `provideClientHydration()` call in newly created Angular applications with SSR. --- packages/schematics/angular/server/index.ts | 6 ++++-- packages/schematics/angular/server/index_spec.ts | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/schematics/angular/server/index.ts b/packages/schematics/angular/server/index.ts index 77e8f4489292..418fec81070c 100644 --- a/packages/schematics/angular/server/index.ts +++ b/packages/schematics/angular/server/index.ts @@ -9,7 +9,6 @@ import { JsonValue, Path, basename, dirname, join, normalize } from '@angular-devkit/core'; import { Rule, - SchematicContext, SchematicsException, Tree, apply, @@ -222,7 +221,10 @@ export default function (options: ServerOptions): Rule { addRootProvider( options.project, ({ code, external }) => - code`${external('provideClientHydration', '@angular/platform-browser')}()`, + code`${external('provideClientHydration', '@angular/platform-browser')}(${external( + 'withEventReplay', + '@angular/platform-browser', + )}())`, ), ]); }; diff --git a/packages/schematics/angular/server/index_spec.ts b/packages/schematics/angular/server/index_spec.ts index dd81f4996825..130d4bf05cd3 100644 --- a/packages/schematics/angular/server/index_spec.ts +++ b/packages/schematics/angular/server/index_spec.ts @@ -95,7 +95,7 @@ describe('Server Schematic', () => { it(`should add 'provideClientHydration' to the providers list`, async () => { const tree = await schematicRunner.runSchematic('server', defaultOptions, appTree); const contents = tree.readContent('/projects/bar/src/app/app.module.ts'); - expect(contents).toContain(`provideClientHydration()`); + expect(contents).toContain(`provideClientHydration(withEventReplay())`); }); }); @@ -138,7 +138,7 @@ describe('Server Schematic', () => { it(`should add 'provideClientHydration' to the providers list`, async () => { const tree = await schematicRunner.runSchematic('server', defaultOptions, appTree); const contents = tree.readContent('/projects/bar/src/app/app.config.ts'); - expect(contents).toContain(`provideClientHydration()`); + expect(contents).toContain(`provideClientHydration(withEventReplay())`); }); });