Skip to content

Commit 508d97d

Browse files
Pawel Kozlowskialan-agius4
Pawel Kozlowski
authored andcommittedMar 29, 2024·
feat(@schematics/angular): use ngZoneEventCoalescing option by default (module bootstrap)
This commit enables ngZoneEventCoalescing by default for NgModule-based applications.
1 parent 7258837 commit 508d97d

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed
 

Diff for: ‎packages/schematics/angular/application/files/module-files/src/main.ts.template

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33

44
import { AppModule } from './app/app.module';
55

6-
<% if(!!viewEncapsulation) { %>
76
platformBrowserDynamic().bootstrapModule(AppModule, {
8-
defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %>
7+
ngZoneEventCoalescing: true<% if(!!viewEncapsulation) { %>,
8+
defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } %>
99
})
10-
.catch(err => console.error(err));<% } else { %>
11-
platformBrowserDynamic().bootstrapModule(AppModule)
1210
.catch(err => console.error(err));
13-
<% } %>

Diff for: ‎packages/schematics/angular/application/index_spec.ts

+22
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,14 @@ describe('Application Schematic', () => {
540540
expect(moduleFiles.length).toEqual(0);
541541
});
542542

543+
it('should enable zone event coalescing by default', async () => {
544+
const options = { ...defaultOptions, standalone: true };
545+
546+
const tree = await schematicRunner.runSchematic('application', options, workspaceTree);
547+
const appConfig = tree.readContent('/projects/foo/src/app/app.config.ts');
548+
expect(appConfig).toContain('provideZoneChangeDetection({eventCoalescing: true})');
549+
});
550+
543551
it('should create a standalone component', async () => {
544552
const options = { ...defaultOptions, standalone: true };
545553

@@ -575,6 +583,20 @@ describe('Application Schematic', () => {
575583
});
576584

577585
describe('standalone=false', () => {
586+
it('should add the ngZoneEventCoalescing option by default', async () => {
587+
const tree = await schematicRunner.runSchematic(
588+
'application',
589+
{
590+
...defaultOptions,
591+
standalone: false,
592+
},
593+
workspaceTree,
594+
);
595+
596+
const content = tree.readContent('/projects/foo/src/main.ts');
597+
expect(content).toContain('ngZoneEventCoalescing: true');
598+
});
599+
578600
it(`should set 'defaultEncapsulation' in main.ts when 'ViewEncapsulation' is provided`, async () => {
579601
const tree = await schematicRunner.runSchematic(
580602
'application',

0 commit comments

Comments
 (0)
Please sign in to comment.