Zoneless async router guards break change detection
See original GitHub issueπ bug report
Affected Package
The issue is caused by package @angular/routerIs this a regression?
Probably notDescription
Async router guards that run outside of zone break change detection.π¬ Minimal Reproduction
https://stackblitz.com/edit/angular-zoneless-guard-issue?file=src%2Fapp%2Fapp.module.ts
Change detection is triggered when clicking the button on the eagerly loaded component but it is not triggered when clicking the button on the lazy loaded component as itβs running outside of zone.
Even if async guards that run outside of zone are a rare case, it can happen and produce issues like with @angular/fire here https://github.com/angular/angularfire/issues/2453 or https://github.com/angular/angularfire/issues/2355.
Maybe the router should get back in the zone once the guard emits the value somewhere after the routing guard management here: https://github.com/angular/angular/blob/f930e75a809a1e21369050884c20f42a350c411f/packages/router/src/router.ts#L590-L631
Should I try to shoot a PR?
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:7 (5 by maintainers)
Top GitHub Comments
I played with it a bit more and it appears that it can be simplified using an operator that wraps all notifications into a call to
NgZone.run
:This can then be used together with
dezone
, see StackBlitz.I will try to check this one.