Skip to content

Commit

Permalink
feat(@schematics/angular): use ngZoneEventCoalescing option by defaul…
Browse files Browse the repository at this point in the history
…t (module bootstrap)

This commit enables ngZoneEventCoalescing by default for NgModule-based applications.
  • Loading branch information
Pawel Kozlowski authored and alan-agius4 committed Mar 29, 2024
1 parent 7258837 commit 508d97d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
<% } %>
22 changes: 22 additions & 0 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 508d97d

Please sign in to comment.