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

Ember.Route 'enter' hook missing _super() call will die with unhelpful error #11136

Closed
glennfu opened this issue May 12, 2015 · 6 comments
Closed

Comments

@glennfu
Copy link

glennfu commented May 12, 2015

I've been using an "enter" hook on my route to set up some connections to Pusher that my app uses, and an "exit" hook to remove them. I'm not sure what round of googling suggested me to use this, but I was using it without calling this._super(). In Ember 1.10.0, this was totally fine and I wasn't given any warnings or messages. Once I upgraded to Ember 1.11.1, the app just died and FireFox gave the following error:

Error while processing route: stories.index this.connections is undefined

Chrome was a bit more helpful and said:

Error while processing route: stories.index Cannot read property 'push' of undefined TypeError: Cannot read property 'push' of undefined

and pointed me to EmberObject.default.extend.render. The solution, as @runspired offered, was to call this.super().

Here's a JSBin in case that's necessary: http://emberjs.jsbin.com/kilohiquda/1/

Googling didn't help me out so hopefully people having this problem will find this post. I think the best solution in my mind would be to have Ember more gracefully handle this error and let the user know where they messed up.

Edit: Maybe it would be nice to mention as a 1.10 -> 1.11 transition/migration detail since that's when it changed.

@selvagsz
Copy link

@glennfu enter is a private api. Use activate instead. And, I agree some assertions will be helpful though

@runspired
Copy link
Contributor

@selvagsz it maybe private now, but there was a time that it was used widely in examples as an easy way to reset scrollTop, which is what I was using it for. It was maybe the oldest piece of original code left in my app, and so when this happened it took me well over a day to trace down the error.

@rwjblue
Copy link
Member

rwjblue commented May 13, 2015

It is always a good idea to do this._super.apply(this, arguments) (or the much better looking ES2015 version: this._super(...arguments);) when implementing framework methods or hooks.

The enter method has been marked as private since prior to 1.0.0.


It may be possible to ensure that _super is called as I mentioned above from an app linting perspective, but I do not see a way that Ember could determine this at runtime...

@runspired
Copy link
Contributor

@rwjblue it's been marked, but that hasn't stopped the examples. If you google "ember reset scrollTop", the second link (first non ember-docs link) is this: http://stackoverflow.com/questions/13120474/emberjs-scroll-to-top-when-changing-view

@rwjblue
Copy link
Member

rwjblue commented May 13, 2015

@runspired - Sadly, I do not have the power to make all examples ever use only public API's and give good advice. 😸

In the end, it really isn't an issue of public/private, I can not think of a way to do what this issue is requesting (to enforce this._super usage by Ember) without also breaking the capability to override things. It might be able to be done via a build step in Ember CLI though..

@rwjblue
Copy link
Member

rwjblue commented Aug 1, 2015

Ok, this is pretty stale, and the solution is to call this._super when overriding hooks (in this case a private one). I'm going to close as I don't really see any other way forward for now.

I'm happy to reopen if others have a better idea...

@rwjblue rwjblue closed this as completed Aug 1, 2015
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

4 participants