Skip to content

Commit cc91372

Browse files
committed
fix(@schematics/angular): move 'provideZoneChangeDetection' to the root module
1 parent 9b3a6f6 commit cc91372

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

packages/schematics/angular/application/files/module-files/src/app/app__typeSeparator__module.ts.template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NgModule, provideBrowserGlobalErrorListeners } from '@angular/core';
1+
import { NgModule, provideBrowserGlobalErrorListeners<% if(!zoneless) { %>, provideZoneChangeDetection<% } %> } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
33
<% if (routing) { %>
44
import { AppRoutingModule } from './app-routing<%= typeSeparator %>module';<% } %>
@@ -13,7 +13,8 @@ import { App } from './app<%= suffix %>';
1313
AppRoutingModule<% } %>
1414
],
1515
providers: [
16-
provideBrowserGlobalErrorListeners()
16+
provideBrowserGlobalErrorListeners(),<% if(!zoneless) { %>
17+
provideZoneChangeDetection({ eventCoalescing: true }),<% } %>
1718
],
1819
bootstrap: [App]
1920
})
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<% if(!!viewEncapsulation) { %>import { ViewEncapsulation } from '@angular/core';
2-
<% }%><% if(!zoneless) { %>import { provideZoneChangeDetection } from '@angular/core';
32
<% }%>import { platformBrowser } from '@angular/platform-browser';
43
import { AppModule } from './app/app<%= typeSeparator %>module';
54

65
platformBrowser().bootstrapModule(AppModule, {
7-
<% if(!zoneless) { %> applicationProviders: [provideZoneChangeDetection({ eventCoalescing: true })], <% } %>
86
<% if(!!viewEncapsulation) { %> defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } %>
97
})
108
.catch(err => console.error(err));

packages/schematics/angular/application/index_spec.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,8 @@ describe('Application Schematic', () => {
698698
workspaceTree,
699699
);
700700

701-
const content = tree.readContent('/projects/foo/src/main.ts');
702-
expect(content).toContain(
703-
'applicationProviders: [provideZoneChangeDetection({ eventCoalescing: true })]',
704-
);
701+
const content = tree.readContent('/projects/foo/src/app/app-module.ts');
702+
expect(content).toContain('provideZoneChangeDetection({ eventCoalescing: true })');
705703
});
706704

707705
it(`should set 'defaultEncapsulation' in main.ts when 'ViewEncapsulation' is provided`, async () => {
@@ -892,6 +890,17 @@ describe('Application Schematic', () => {
892890
});
893891

894892
describe('standalone: false', () => {
893+
it('should add the provideZoneChangeDetection with event coalescing option by default with zone.js apps', async () => {
894+
const options = {
895+
...defaultOptions,
896+
standalone: false,
897+
zoneless: false,
898+
fileNameStyleGuide: '2016' as const,
899+
};
900+
const tree = await schematicRunner.runSchematic('application', options, workspaceTree);
901+
const content = tree.readContent('/projects/foo/src/app/app.module.ts');
902+
expect(content).toContain('provideZoneChangeDetection({ eventCoalescing: true })');
903+
});
895904
it('should create a component with the correct template and style urls', async () => {
896905
const options = {
897906
...defaultOptions,

packages/schematics/angular/utility/standalone/rules_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ describe('standalone utilities', () => {
422422
assertContains(content, `import { SOME_TOKEN } from '@my/module';`);
423423
assertContains(
424424
content,
425-
`providers: [provideBrowserGlobalErrorListeners(),{ provide: SOME_TOKEN, useValue: 123 }]`,
425+
`providers: [provideBrowserGlobalErrorListeners(),{ provide: SOME_TOKEN, useValue: 123 },]`,
426426
);
427427
});
428428

0 commit comments

Comments
 (0)