Content-Length: 287032 | pFad | http://github.com/angular/angular/commit/796a928514670b72ca75013bf5063b35e3648b1e

63 fix(core): do not run change detection on global error events · angular/angular@796a928 · GitHub
Skip to content

Commit 796a928

Browse files
committed
fix(core): do not run change detection on global error events
This commit wraps the `error` and `unhandledrejection` event listeners so they are installed outside of the Angular zone, because otherwise they trigger change detection whenever the event callbacks are invoked.
1 parent 037dede commit 796a928

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/core/src/error_handler.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,19 @@ const globalErrorListeners = new InjectionToken<void>(ngDevMode ? 'GlobalErrorLi
104104
e.preventDefault();
105105
};
106106

107-
window.addEventListener('unhandledrejection', rejectionListener);
108-
window.addEventListener('error', errorListener);
107+
const setupEventListeners = () => {
108+
window.addEventListener('unhandledrejection', rejectionListener);
109+
window.addEventListener('error', errorListener);
110+
};
111+
112+
// Angular doesn't have to run change detection whenever any asynchronous tasks are invoked in
113+
// the scope of this functionality.
114+
if (typeof Zone !== 'undefined') {
115+
Zone.root.run(setupEventListeners);
116+
} else {
117+
setupEventListeners();
118+
}
119+
109120
inject(DestroyRef).onDestroy(() => {
110121
window.removeEventListener('error', errorListener);
111122
window.removeEventListener('unhandledrejection', rejectionListener);

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/angular/angular/commit/796a928514670b72ca75013bf5063b35e3648b1e

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy