File tree Expand file tree Collapse file tree
packages/schematics/angular/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import {
2222} from '@angular-devkit/schematics' ;
2323import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks' ;
2424import { posix } from 'node:path' ;
25+ import { addRootProvider } from '../utility' ;
2526import {
2627 NodeDependencyType ,
2728 addPackageJsonDependency ,
@@ -220,6 +221,11 @@ export default function (options: ServerOptions): Rule {
220221 updateConfigFileBrowserBuilder ( options , tsConfigDirectory ) ,
221222 ] ) ,
222223 addDependencies ( ) ,
224+ addRootProvider (
225+ options . project ,
226+ ( { code, external } ) =>
227+ code `${ external ( 'provideClientHydration' , '@angular/platform-browser' ) } ()` ,
228+ ) ,
223229 ] ) ;
224230 } ;
225231}
Original file line number Diff line number Diff line change @@ -91,6 +91,12 @@ describe('Server Schematic', () => {
9191 expect ( contents . compilerOptions . types ) . toEqual ( [ 'node' ] ) ;
9292 expect ( contents . files ) . toEqual ( [ 'src/main.ts' , 'src/main.server.ts' ] ) ;
9393 } ) ;
94+
95+ it ( `should add 'provideClientHydration' to the providers list` , async ( ) => {
96+ const tree = await schematicRunner . runSchematic ( 'server' , defaultOptions , appTree ) ;
97+ const contents = tree . readContent ( '/projects/bar/src/app/app.module.ts' ) ;
98+ expect ( contents ) . toContain ( `provideClientHydration()` ) ;
99+ } ) ;
94100 } ) ;
95101
96102 describe ( 'standalone application' , ( ) => {
@@ -128,6 +134,12 @@ describe('Server Schematic', () => {
128134 const contents = tree . readContent ( filePath ) ;
129135 expect ( contents ) . toContain ( `const serverConfig: ApplicationConfig = {` ) ;
130136 } ) ;
137+
138+ it ( `should add 'provideClientHydration' to the providers list` , async ( ) => {
139+ const tree = await schematicRunner . runSchematic ( 'server' , defaultOptions , appTree ) ;
140+ const contents = tree . readContent ( '/projects/bar/src/app/app.config.ts' ) ;
141+ expect ( contents ) . toContain ( `providers: [provideClientHydration()]` ) ;
142+ } ) ;
131143 } ) ;
132144
133145 describe ( 'Legacy browser builder' , ( ) => {
You can’t perform that action at this time.
0 commit comments