You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Attempted to handle event reloadRecord on <xyz> while in state root.loading" when reloading a belongsTo association multiple times simultaneously
#5423
I have a situation where I render a same component twice on the same page. This component reloads a belongsTo association at initialization. So something like:
// template.hbs
{{x-component model=model}}
{{! ...further on the page... !}}
{{x-component model=model}}
Attempted to handle event reloadRecord on while in state root.loading.
I figured the issue is that since the components are rendered on the same page, the two reloads of the association are fired at "around" the same time. However, further down the stack inside Ember Data, one reload necessarily happens before the other and changes the state of the internal model. When the second reload is processed, it fails at https://github.com/emberjs/data/blob/v3.0.2/addon/-private/system/model/internal-model.js#L749 because the previous one has changed the state.
I tried observing the state before the reload, i.e.
// x-component/component.jsexportdefaultComponent.extend({init(){this._super(...arguments);// the following line always prints 'false'console.log(this.get('model').belongsTo('assoc').internalModel.isLoading());// the following line always prints 'root.loaded.saved'console.log(this.get('model').belongsTo('assoc').internalModel.currentState.stateName);this.get('model').belongsTo('assoc').reload();}});
but it looks like the reload calls really happen at around the same time, or in any case before Ember Data has changed the state due to one reload being processed.
I could of course reload the association in the parent instead of inside the component but ideally I'd like to keep this logic contained within the component.
Any thoughts on how to approach this?
The text was updated successfully, but these errors were encountered:
I have a situation where I render a same component twice on the same page. This component reloads a belongsTo association at initialization. So something like:
This throws an error
I figured the issue is that since the components are rendered on the same page, the two reloads of the association are fired at "around" the same time. However, further down the stack inside Ember Data, one reload necessarily happens before the other and changes the state of the internal model. When the second reload is processed, it fails at https://github.com/emberjs/data/blob/v3.0.2/addon/-private/system/model/internal-model.js#L749 because the previous one has changed the state.
I tried observing the state before the reload, i.e.
but it looks like the
reload
calls really happen at around the same time, or in any case before Ember Data has changed the state due to one reload being processed.I could of course reload the association in the parent instead of inside the component but ideally I'd like to keep this logic contained within the component.
Any thoughts on how to approach this?
The text was updated successfully, but these errors were encountered: