-
-
Notifications
You must be signed in to change notification settings - Fork 4.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
Injecting router service into EmberRouter infinitely recurses #17791
Comments
|
@efx that code snippet is not injecting the router service, I believe that is a different situation! |
I can also confirm this behaviour, on Ember 3.8 Code: import EmberRouter from '@ember/routing/router';
import config from './config/environment';
import { set } from '@ember/object';
import { inject as service } from '@ember/service';
const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL,
router: service(),
routeHelpers: service(),
init() {
this._super(...arguments);
this.router.on('routeDidChange', () => {
// tracking with piwik, if the piwik object has been defined
if (typeof _paq === 'object') {
_paq.push(['trackPageView']);
}
// tracking with google analytics, if the ga method has been defined
if (typeof ga === 'function') {
return ga('send', 'pageview', {
'page': this.get('url'),
'title': this.get('url')
});
}
// set current route to the onla accordion, which will open
// it's corresponding accordion element
var onlaController = this.routeHelpers.controllerFor('onla');
set(onlaController, 'currentRouteName', this.router.currentRouteName);
});
}
}); Exception:
I wanted to replace 'didTransition' function in my DEPRECATION: You attempted to override the "didTransition" method which is deprecated. Please inject the router service and listen to the "routeDidChange" event. [deprecation id: deprecate-router-events] See https://emberjs.com/deprecations/v3.x#toc_deprecate-router-events for more details. |
@ursqontis for the record, you can listen to the router events from within the router. You should just need to do |
If this is intended to be the public API for doing this in |
I think it should generally be considered a bug if service injections fail. The issue in this case is that the router service itself gets router:main injected into it. What is happening here is:
The fix here is to make the router service not eagerly lookup the router:main... |
@rwjblue, how hard a lift is that? I’m going to have a little time in the next few weeks when I could probably hit this if the path is clear! |
Sorry I missed this at the time @chriskrycho. I think it should be fairly straightforward (e.g. "not too hard") to remove the auto-injection, and only look up the router service when actually pulled on. |
Hi all! closed by #19405 |
@snewcomer @rwjblue since an other refactoring, the routerService is a 'private' property of the EmberRouter, https://github.com/emberjs/ember.js/blob/master/packages/@ember/-internals/routing/lib/system/router.ts#L164 I wonder if we can just make this prop public (though it still looks kind of weird to me, accessing a service from an object, aiming to wrap some behaviors of this specific object). |
Code sample:
Reproduction: https://github.com/ember-triage/emberjs-17791
P.S. Injecting
router
intoEmberRouter
also breaks.The text was updated successfully, but these errors were encountered: