diff --git a/packages/schematics/angular/application/files/module-files/src/main.ts.template b/packages/schematics/angular/application/files/module-files/src/main.ts.template index e830262f190f..ac03d58c6153 100644 --- a/packages/schematics/angular/application/files/module-files/src/main.ts.template +++ b/packages/schematics/angular/application/files/module-files/src/main.ts.template @@ -3,11 +3,8 @@ import { AppModule } from './app/app.module'; -<% if(!!viewEncapsulation) { %> platformBrowserDynamic().bootstrapModule(AppModule, { - defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %> + ngZoneEventCoalescing: true<% if(!!viewEncapsulation) { %>, + defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } %> }) - .catch(err => console.error(err));<% } else { %> -platformBrowserDynamic().bootstrapModule(AppModule) .catch(err => console.error(err)); -<% } %> \ No newline at end of file diff --git a/packages/schematics/angular/application/index_spec.ts b/packages/schematics/angular/application/index_spec.ts index ee053372b30b..419f46a6a4f2 100644 --- a/packages/schematics/angular/application/index_spec.ts +++ b/packages/schematics/angular/application/index_spec.ts @@ -540,6 +540,14 @@ describe('Application Schematic', () => { expect(moduleFiles.length).toEqual(0); }); + it('should enable zone event coalescing by default', async () => { + const options = { ...defaultOptions, standalone: true }; + + const tree = await schematicRunner.runSchematic('application', options, workspaceTree); + const appConfig = tree.readContent('/projects/foo/src/app/app.config.ts'); + expect(appConfig).toContain('provideZoneChangeDetection({eventCoalescing: true})'); + }); + it('should create a standalone component', async () => { const options = { ...defaultOptions, standalone: true }; @@ -575,6 +583,20 @@ describe('Application Schematic', () => { }); describe('standalone=false', () => { + it('should add the ngZoneEventCoalescing option by default', async () => { + const tree = await schematicRunner.runSchematic( + 'application', + { + ...defaultOptions, + standalone: false, + }, + workspaceTree, + ); + + const content = tree.readContent('/projects/foo/src/main.ts'); + expect(content).toContain('ngZoneEventCoalescing: true'); + }); + it(`should set 'defaultEncapsulation' in main.ts when 'ViewEncapsulation' is provided`, async () => { const tree = await schematicRunner.runSchematic( 'application',