-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug(router-store): emitting guard results from state changes can cause infinite loops in certain circumstances #2829
Comments
Some details around this bug: Current behavoir of Angular Router is to navigate to When such Guard is guarding the root path itself, router-store reacts to the change in the store a bit later than it should, and misses the @damienwebdev correctly identified the line:
The code then proceeds and checks It mismatches and triggers another re-routing, which triggers another guard and so on, getting everything into the loop. While not being the ideal solution, improving the matching of URLs solves the issue. |
Minimal reproduction of the bug/regression with instructions:
^v8.0.0 https://stackblitz.com/edit/angular-8-getting-started-1koz3g
^v10.0.0 https://stackblitz.com/edit/angular-ivy-bf2jo8
Expected behavior:
Not an infinite loop, instead a simple navigation cancel resulting in a white-screen.
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):
@ngrx/platform: v8.6.0
@angular/core: v8.0.0
Other information:
This exists in develop as well, but I simply made a repro on the version of Angular in which I found the bug.
The bug is a result of two things:
The router-store code, which is quite old (pre-ngrx 4), assumes that state reduction follows IMMEDIATELY after an action is dispatched. Yet, this isn't always the case, given that actions are stacked onto an rxjs queue. This means that when this check occurs the trigger value is
RouterTrigger.NONE
instead ofRouterTrigger.ROUTER
which results in an infinite loop as it triggers another navigation to the root re-checking the guard.I would be willing to submit a PR to fix this issue
[x] Yes (Assistance is provided if you need help submitting a pull request)
[] No
The text was updated successfully, but these errors were encountered: