State cannot be accessed in init hook in Ember 3.5.1
See original GitHub issueI use ember-redux on a project, and ocassionally I need to make a request from init
hook which uses some data from the global state, currently I’m on Ember 3.1.1
and trying to update to 3.5.1
, but the problem I’ve encountered holds me down.
Potentially changing a single line in connect.js
fixes the problem:
if (WrappedComponent.hasOwnProperty('extend')) {
-> if (WrappedComponent.extend) {
Because of when the call to the store is made.
In ember-object
connector, it happens before WrappedComponent
’s init
hook,
while for es-2015
, es-2019
it happens later.
I’ve prepared a reproduction of the problem: https://github.com/BobrImperator/redux-state-in-init
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
scheduleOne('afterRender') in a Controller.init() does not work ...
Hello, My code : // app/router.js import EmberRouter from '@ember/routing/router'; import config from './config/environment'; const Router ...
Read more >Ember component: variable set before calling init? · Issue ...
So in my understanding it was not possible to access the attributes at the init state, only after did ReceiveAttrs . Guess I...
Read more >How to access ember model in on("init") in object controller
The short answer is that you can't. Controllers are instantiated by the container before the route has had a chance to set the...
Read more >Ember Route Hooks — A Complete Look | Alex DiLiberto
A deeper dive outlining each of the most important lifecycle hooks for Ember's internal routing structure.
Read more >The 8 Most Common Mistakes That Ember.js Developers Make
Common Mistake No. 3: Not Calling the Default Implementation in setupController. Routes in Ember have a handful of lifecycle hooks to define application- ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@BobrImperator I was able to solve it (even for 2.18 despite what Travis said during the PR build)
https://github.com/ember-redux/ember-redux/pull/182
I’ll need to build a fresh 2.18 ember-cli app quick to confirm it’s g2g but if so (fingers crossed) I’ll publish a new version of this library next week. Can you confirm the master branch of this fixes your use case? I tried to take your example and throw that into the app as a test case (to confirm this is working for EmberObject from ember 2.18+)
wow so prod env only breaks but dev/test is fine? I’ll look into this next week as I’m traveling atm and won’t have immediate access to jump in and triage this.
About the es-2015 init request we can’t alter that function for backwards compat reasons but the issue here seems to be that classic ember component (not class keyword) is dropping into the else block instead of using the EmberObject case. Can you inspect and report back with what condition is different between dev and prod? This might help me get some help from the core team about why this differs so much between envs