Skip to content
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

Navigation is cancelled by any action during an async guard checking #354

Closed
kondi opened this issue Sep 6, 2017 · 0 comments
Closed

Navigation is cancelled by any action during an async guard checking #354

kondi opened this issue Sep 6, 2017 · 0 comments

Comments

@kondi
Copy link
Contributor

kondi commented Sep 6, 2017

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request

What is the current behavior?

The navigation is cancelled when an action dispatched during a guard checking.

A simple timeline:

  1. Navigate to a page which has an async guard
  2. Before the guard is resolved, emit an action
  3. The navigation will be cancelled and relaunched even if the guard accepts the navigation

Expected behavior:

Simple timeline:

  1. Navigate to a page which has an async guard
  2. Before the guard is resolved, emit an action
  3. The navigation should not be cancelled when the guard accepts the navigation

Minimal reproduction of the problem with instructions:

(For a simple reproduction see my unit test: https://github.com/kondi/platform/blob/13feb6c12118955473f351e6fc7e3575699d93f3/modules/router-store/spec/integration.spec.ts#L377.)

Detailed plunker example:
https://plnkr.co/edit/VVe26uhP3qoNARyhPmi1?p=preview

After clicking on button, you can see in the console:

[Router] /page NavigationStart
[Router] /page NavigationCancel
[Router] /page NavigationStart
[Router] /page NavigationEnd

However you should see:

[Router] /page NavigationStart
[Router] /page NavigationEnd

Explanation of the attached plunker example:

  1. Click on the button, 'GO_TO_PAGE' action is dispatched
  2. AppEffects.goToPage$ initiates a navigation to /page (using navigateByUrl)
  3. AppEffects.whatever$ starts to wait half second
  4. Async AppGuard is activated which starts to wait 1 second
  5. AppEffects.whatever$ has finished waiting, emits any action (without any other side-effect)
  6. AppGuard has finished waiting, returns true
  7. Navigation is cancelled and started again for /page
  8. Async AppGuard is activated again which starts to wait 1 second
  9. AppGuard has finished waiting, returns true
  10. Navigation is finished for /page

The expected behavior is to skip step 6, 7 and 8.

Version of affected browser(s),operating system(s), npm, node and ngrx:

@ngrx/router-store: 4.0.4

Other information:

You can "fix" this on the user side by not registering the routerReducer, or registering it, but with different name.
I have a simple fix for the library too, PR is on the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant