Content-Length: 369894 | pFad | https://github.com/angular/angular/commit/219f41d049cf6798f81fbb393b4e23b2a030ff48

CD fix(router): Prevent dangling promise rejections from internal naviga… · angular/angular@219f41d · GitHub
Skip to content

Commit 219f41d

Browse files
atscottAndrewKushnir
authored andcommitted
fix(router): Prevent dangling promise rejections from internal navigations (#60162)
Though the plan is to change the default behavior or the router to instead resolve the navigation promise with `false` to match all other failed navigations, we should still prevent dangling promise rejections from navigations triggered internally when developers opt to use the old (current) behavior. PR Close #60162
1 parent 4c22e65 commit 219f41d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/router/src/directives/router_link.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
ɵRuntimeError as RuntimeError,
2222
SimpleChanges,
2323
ɵɵsanitizeUrlOrResourceUrl,
24+
ɵINTERNAL_APPLICATION_ERROR_HANDLER,
25+
inject,
2426
} from '@angular/core';
2527
import {Subject, Subscription} from 'rxjs';
2628

@@ -202,6 +204,8 @@ export class RouterLink implements OnChanges, OnDestroy {
202204
/** @internal */
203205
onChanges = new Subject<RouterLink>();
204206

207+
private readonly applicationErrorHandler = inject(ɵINTERNAL_APPLICATION_ERROR_HANDLER);
208+
205209
constructor(
206210
private router: Router,
207211
private route: ActivatedRoute,
@@ -349,7 +353,9 @@ export class RouterLink implements OnChanges, OnDestroy {
349353
state: this.state,
350354
info: this.info,
351355
};
352-
this.router.navigateByUrl(urlTree, extras);
356+
this.router.navigateByUrl(urlTree, extras).catch((e) => {
357+
this.applicationErrorHandler(e);
358+
});
353359

354360
// Return `false` for `<a>` elements to prevent default action
355361
// and cancel the native behavior, since the navigation is handled

packages/router/src/router.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
ɵConsole as Console,
1515
ɵPendingTasksInternal as PendingTasks,
1616
ɵRuntimeError as RuntimeError,
17+
ɵINTERNAL_APPLICATION_ERROR_HANDLER,
18+
EnvironmentInjector,
1719
} from '@angular/core';
1820
import {Observable, Subject, Subscription, SubscriptionLike} from 'rxjs';
1921

@@ -114,6 +116,7 @@ export class Router {
114116
private readonly urlSerializer = inject(UrlSerializer);
115117
private readonly location = inject(Location);
116118
private readonly urlHandlingStrategy = inject(UrlHandlingStrategy);
119+
private readonly injector = inject(EnvironmentInjector);
117120

118121
/**
119122
* The private `Subject` type for the public events exposed in the getter. This is used internally
@@ -324,7 +327,9 @@ export class Router {
324327
}
325328

326329
const urlTree = this.parseUrl(url);
327-
this.scheduleNavigation(urlTree, source, restoredState, extras);
330+
this.scheduleNavigation(urlTree, source, restoredState, extras).catch((e) => {
331+
this.injector.get(ɵINTERNAL_APPLICATION_ERROR_HANDLER)(e);
332+
});
328333
}
329334

330335
/** The current URL. */

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: https://github.com/angular/angular/commit/219f41d049cf6798f81fbb393b4e23b2a030ff48

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy