Skip to content

bug(router-store): emitting guard results from state changes can cause infinite loops in certain circumstances #2829

@damienwebdev

Description

@damienwebdev

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:

  1. A guard on the root that utilizes state for its observable emission.
  2. A race-condition here..

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 of RouterTrigger.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions