GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): unsubscribe from the `onError` when the root view is remov… · angular/angular@35309bb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/core
    • src
      • application_ref.ts
    • test/acceptance
      • bootstrap_spec.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/src/application_ref.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/application_ref.ts
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,17 @@ export class PlatformRef {
328328
if (!exceptionHandler) {
329329
throw new Error('No ErrorHandler. Is platform module (BrowserModule) included?');
330330
}
331-
moduleRef.onDestroy(() => remove(this._modules, moduleRef));
332-
ngZone!.runOutsideAngular(() => ngZone!.onError.subscribe({
333-
next: (error: any) => {
334-
exceptionHandler.handleError(error);
335-
}
336-
}));
331+
ngZone!.runOutsideAngular(() => {
332+
const subscription = ngZone!.onError.subscribe({
333+
next: (error: any) => {
334+
exceptionHandler.handleError(error);
335+
}
336+
});
337+
moduleRef.onDestroy(() => {
338+
remove(this._modules, moduleRef);
339+
subscription.unsubscribe();
340+
});
341+
});
337342
return _callAndReportToErrorHandler(exceptionHandler, ngZone!, () => {
338343
const initStatus: ApplicationInitStatus = moduleRef.injector.get(ApplicationInitStatus);
339344
initStatus.runInitializers();
Collapse file

‎packages/core/test/acceptance/bootstrap_spec.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/acceptance/bootstrap_spec.ts
+18-2Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ApplicationRef, COMPILER_OPTIONS, Component, destroyPlatform, NgModule, TestabilityRegistry, ViewEncapsulation} from '@angular/core';
9+
import {ApplicationRef, COMPILER_OPTIONS, Component, destroyPlatform, NgModule, NgZone, TestabilityRegistry, ViewEncapsulation} from '@angular/core';
1010
import {expect} from '@angular/core/testing/src/testing_internal';
1111
import {BrowserModule} from '@angular/platform-browser';
1212
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
@@ -227,6 +227,22 @@ describe('bootstrap', () => {
227227
}));
228228
});
229229

230+
describe('PlatformRef cleanup', () => {
231+
it('should unsubscribe from `onError` when Injector is destroyed',
232+
withBody('<my-app></my-app>', async () => {
233+
const TestModule = createComponentAndModule();
234+
235+
const ngModuleRef = await platformBrowserDynamic().bootstrapModule(TestModule);
236+
const ngZone = ngModuleRef.injector.get(NgZone);
237+
238+
expect(ngZone.onError.observers.length).toBe(1);
239+
240+
ngModuleRef.destroy();
241+
242+
expect(ngZone.onError.observers.length).toBe(0);
243+
}));
244+
});
245+
230246
onlyInIvy('options cannot be changed in Ivy').describe('changing bootstrap options', () => {
231247
beforeEach(() => {
232248
spyOn(console, 'error');
@@ -365,4 +381,4 @@ export class MultipleSelectorsAppComponent {
365381
bootstrap: [MultipleSelectorsAppComponent],
366382
})
367383
export class MultipleSelectorsAppModule {
368-
}
384+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.