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

"Attempted to handle event reloadRecord on <xyz> while in state root.loading" when reloading a belongsTo association multiple times simultaneously #5423

Closed
YoranBrondsema opened this issue Apr 6, 2018 · 2 comments · Fixed by #5410

Comments

@YoranBrondsema
Copy link

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}}
// x-component/component.js

export default Component.extend({
  init() {
    this._super(...arguments);

    this.get('model').belongsTo('assoc').reload();
  }
});

This throws an error

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.js

export default Component.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?

@runspired
Copy link
Contributor

This is a bug fixed by #5410

@YoranBrondsema
Copy link
Author

YoranBrondsema commented Apr 6, 2018

Ah sorry, hadn't realized that. Thanks for the quick reply, and looking forward to seeing the PR merged and released!

@bmac bmac closed this as completed in #5410 Apr 6, 2018
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

Successfully merging a pull request may close this issue.

2 participants