From 695d4c5f81cc8af2ec243e6a685e1ce5c41fbaaa Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Fri, 6 Jun 2025 12:54:30 -0700 Subject: [PATCH] fix: Avoid handling promise rejections twice in stability helper `PendingTasks.run` reports rejections of the promise to the `ErrorHandler`. This function already returns a promise that is meant to be handled in the developer's application. If there _is_ handling there, the rejection is handled both in the `PendingTasks.run` and in the developer callsite. This change updates the code to use `PendingTasks.add` instead, which has no built in error handling mechanisms. fixes https://github.com/angular/angular/issues/61932 --- src/zones.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zones.ts b/src/zones.ts index c3e2b2f5e..dc0f7262d 100644 --- a/src/zones.ts +++ b/src/zones.ts @@ -170,12 +170,12 @@ export const ɵzoneWrap = (it: T, blockUntilFirst: boolean, logLevel // eslint-disable-next-line @typescript-eslint/no-misused-promises return run( () => { - pendingTasks.run(() => ret); + const removeTask = pendingTasks.add(); return new Promise((resolve, reject) => { ret.then( (it) => runInInjectionContext(injector, () => run(() => resolve(it))), (reason) => runInInjectionContext(injector, () => run(() => reject(reason))) - ) + ).finally(removeTask); }); }); } else if (typeof ret === 'function' && taskDone) {