Skip to content

feat(@schematics/angular): Add global error listeners to new app generation #30053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NgModule<% if(experimentalZoneless) { %>, provideExperimentalZonelessChangeDetection<% } %> } from '@angular/core';
import { NgModule, provideBrowserGlobalErrorListeners<% if(experimentalZoneless) { %>, provideExperimentalZonelessChangeDetection<% } %> } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
<% if (routing) { %>
import { AppRoutingModule } from './app-routing-module';<% } %>
Expand All @@ -12,7 +12,10 @@ import { App } from './app';
BrowserModule<% if (routing) { %>,
AppRoutingModule<% } %>
],
providers: [<% if (experimentalZoneless) { %>provideExperimentalZonelessChangeDetection()<% } %>],
providers: [
provideBrowserGlobalErrorListeners()<% if (experimentalZoneless) { %>,
provideExperimentalZonelessChangeDetection()<% } %>
],
bootstrap: [App]
})
export class AppModule { }
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ApplicationConfig, <% if(!experimentalZoneless) { %>provideZoneChangeDetection<% } else { %>provideExperimentalZonelessChangeDetection<% } %> } from '@angular/core';<% if (routing) { %>
import { ApplicationConfig, provideBrowserGlobalErrorListeners, <% if(!experimentalZoneless) { %>provideZoneChangeDetection<% } else { %>provideExperimentalZonelessChangeDetection<% } %> } from '@angular/core';<% if (routing) { %>
import { provideRouter } from '@angular/router';

import { routes } from './app.routes';<% } %>

export const appConfig: ApplicationConfig = {
providers: [<% if(experimentalZoneless) { %>provideExperimentalZonelessChangeDetection()<% } else { %>provideZoneChangeDetection({ eventCoalescing: true })<% } %><% if (routing) {%>, provideRouter(routes)<% } %>]
providers: [
provideBrowserGlobalErrorListeners(),
<% if(experimentalZoneless) { %>provideExperimentalZonelessChangeDetection()<% } else { %>provideZoneChangeDetection({ eventCoalescing: true })<% } %>,
<% if (routing) {%>provideRouter(routes)<% } %>
]
};
2 changes: 1 addition & 1 deletion packages/schematics/angular/service-worker/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('Service Worker Schematic', () => {
const tree = await schematicRunner.runSchematic('service-worker', defaultOptions, appTree);
const content = tree.readContent('/projects/bar/src/app/app.config.ts');
expect(content).toContain(
`import { ApplicationConfig, provideZoneChangeDetection, isDevMode } from '@angular/core';`,
`import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection, isDevMode } from '@angular/core';`,
);
});

Expand Down
19 changes: 15 additions & 4 deletions packages/schematics/angular/utility/standalone/rules_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,10 @@ describe('standalone utilities', () => {
const content = readFile('app/app-module.ts');

assertContains(content, `import { SOME_TOKEN } from '@my/module';`);
assertContains(content, `providers: [{ provide: SOME_TOKEN, useValue: 123 }]`);
assertContains(
content,
`providers: [provideBrowserGlobalErrorListeners(),{ provide: SOME_TOKEN, useValue: 123 }]`,
);
});

it('should add a root provider to a standalone app', async () => {
Expand All @@ -442,7 +445,11 @@ describe('standalone utilities', () => {
assertContains(content, `import { provideModule } from '@my/module';`);
assertContains(
content,
`providers: [provideZoneChangeDetection({ eventCoalescing:true }),provideModule([])]`,
`providers: [
provideBrowserGlobalErrorListeners(),
provideZoneChangeDetection({ eventCoalescing:true }),
provideModule([]),
]`,
);
});

Expand All @@ -453,11 +460,12 @@ describe('standalone utilities', () => {
host.overwrite(
getPathWithinProject(configPath),
`
import { ApplicationConfig } from '@angular/core';
import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core';
import { provideRouter } from '@angular/router';

export const appConfig: ApplicationConfig = {
providers: [
provideBrowserGlobalErrorListeners(),
provideRouter([]),
]
};
Expand All @@ -474,7 +482,10 @@ describe('standalone utilities', () => {

const content = readFile('app/app.config.ts');
assertContains(content, `import { provideModule } from '@my/module';`);
assertContains(content, `providers: [provideRouter([]),provideModule([]),]`);
assertContains(
content,
`providers: [provideBrowserGlobalErrorListeners(), provideRouter([]),provideModule([]),]`,
);
});
});
});
19 changes: 9 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading