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

accessing injected router service in the application route causes init to fire repeatedly #17873

Closed
ghost opened this issue Apr 6, 2019 · 3 comments
Labels

Comments

@ghost
Copy link

ghost commented Apr 6, 2019

I expect the #init hook of any route to run once and not repeatedly. When I inject the router service into a route and call this.router.recognize I see the #init hook fire multiple times.
You can see this in the follow application:

  1. git clone https://github.com/efx/poc-bug/ --branch 3.8.1 && cd poc-bug/route-recognize
  2. yarn start

Open your console and you should see the #init log multiple times. If you remove the line that calls this.router.recognize, the init fires once. I verified 3.8.0 and master as of 3.11.0-canary+7da998b3 exhibits the same bug.

@xg-wang
Copy link
Contributor

xg-wang commented Apr 10, 2019

Accessing RouterService in Router will cause circular loop because Router is injected into RouterService https://github.com/emberjs/ember.js/blob/v3.10.0-beta.2/packages/@ember/-internals/routing/lib/services/router.ts#L66. What methods do you need from RouterService during Router init?

@ghost
Copy link
Author

ghost commented Apr 10, 2019

hmm, so this would be a duplicate of #17791?
I needed the on method to register handlers for route transitions.

@ghost
Copy link
Author

ghost commented Jul 26, 2019

Verified this still occurs on 3.11. To be clear, I am accessing the router service from within a route not from the router.
@xg-wang honestly I've forgotten what I was trying to do when I opened this issue. Given I unblocked our application we could close this if expected behavior but I do find this very counter-intuitive and would be curious why this happens. (Updated link of the router service)

@locks locks added the Routing label Apr 19, 2020
@ghost ghost closed this as completed Jun 12, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants