Skip to content

Commit

Permalink
feat(@schematics/angular): integrate withEventReplay() in `provideC…
Browse files Browse the repository at this point in the history
…lientHydration` for new SSR apps

Event Replay is now stable (see angular/angular#57895). This commit adds `withEventReplay()` to the `provideClientHydration()` call in newly created Angular applications with SSR.
  • Loading branch information
alan-agius4 committed Sep 23, 2024
1 parent 26962e4 commit cfca544
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/schematics/angular/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { JsonValue, Path, basename, dirname, join, normalize } from '@angular-devkit/core';
import {
Rule,
SchematicContext,
SchematicsException,
Tree,
apply,
Expand Down Expand Up @@ -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',
)}())`,
),
]);
};
Expand Down
4 changes: 2 additions & 2 deletions packages/schematics/angular/server/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())`);
});
});

Expand Down Expand Up @@ -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())`);
});
});

Expand Down

0 comments on commit cfca544

Please sign in to comment.