Why the route will run twice when i transition back from another route?

Currently i having a route which is use to findAll the record from a model. But the result comeback as an array so in the template I used {{#each}} to loop them. Originally it comeback two records in the array which is the correct behavior. But whenever i try to transition to another route and transition back it will comeback 4 records which is duplicate. It will multiple each time when i try to transition back. I’m not sure which part is missing or having mistake that cause that behavior. Or variable must be destroy when leave the route?


 @task(function* (){
      try {
        let companyList = yield this.store.findAll('list-company');

        return {
            companyList: companyList,
      } catch (e) {
        this.intermediateTransitionTo('error', e);
        throw (e);
      }).restartable() loadModelTask;
    model() {
      try {
        return this.loadModelTask.perform();
      } catch (e) {
        throw (e);

    setupController(controller, model) {
        this._super(controller, model);
        controller.set('companyList', model.companyList);


{{#if loadModelTask.isRunning}}
  {{#each companyList as |comp|}}

Before transition when the route is called

Screenshot from 2021-08-18 14-18-55

After transition back from other page, the record is duplicated

It sounds like you’re using an ember-concurrency task on a Route, in the model() hook?

You can do that, but it’s not going to do what you think. For example, your template will never show loadModelTask.isRunning as true, because the model hook waits to resolve the returned promise before it will render your template at all. To rule out any confusion around this, first try simplifying your model() hook to something like:

async model() {
  let companyList = await this.store.findAll('list-company');
  return { companyList };

Then if you’re still seeing these duplicate records, your problem is likely to be in the way your ember-data model or adapter are working. For example, if they don’t provide stable IDs, each time you fetch from the server you will end up with “new” copies of the data.

Thanks for the suggestion. But I did simplifying my model by following your suggestion but still getting the duplicate records.

Then most likely is the problem you mentioned was the adapter/ember data model are working. But i’m not quite understand about the “don’t provide stable IDs will getting “new” records”, what does it means? And how it triggered the adapter to work?

I mean that if ember-data is showing you four entries, those four entries must all have different IDs from each other. So maybe the IDs are not staying stable. If you can share more about how your model & adapter works we could maybe help further.

Yea, you’re right! The IDs are not staying stable and i found out is backend’s issues. I wouldn’t even figure out if without your help. Thanks ! :grinning_face_with_smiling_eyes: