Ember rendering two duplicate records before refresh


#1

I’ve got an unusual problem. On my backend I have an express.js API feeding ember data. Right after I add a new record to the database (I’m running mongo), and then go to the index page which fetches all records I’ll get duplicate records. When I refresh, the duplicate disappears. It only happens some times, and I’m not sure whats casing it. I checked my backend, and it’s only sending any duplicate information.

I’ve attached link to an image that better illustrates the issue.

http://imgur.com/V4r3jM7


#2

It’s hard to say precisely what’s happening without seeing the code. How are you fetching the data in the model hook? What does the save action look like for adding a new record?


#3

The route which creates the record:

export default Ember.Route.extend({
  model() {
    return this.store.createRecord('library');
  },

  actions: {
    //where newLibrary is the model we passed in from the template
    saveLibrary(newLibrary) {
      newLibrary.save().then(() => this.transitionTo('libraries.index'));
    },

    willTransition() {
      this.controller.get('model').rollbackAttributes();
    }
  }


});

displaying the libraries:

export default Ember.Route.extend({
  model() {
    return this.store.findAll('library');
  },
  actions: {
    //where library is the model passed in from the template
    deleteLibrary(library) {
      let confirmation = confirm('Are you sure?');

      if (confirmation) {
        library.destoryRecord();
      }
    }
  }
});

the api controller sending the data (I’m transpiling with babel for es6 functionality):

import Library from ‘…/…/models/library’;

export default function(req, res) {
  Library.find({}, function(err, libs) {
    if (err) { res.status(400).json(err); }
    res.status(200).json(libs);
  });
}

#4

I might of found the problem, I’m using a JSONSerializer, but forgot to change the RESTAPIADAPTER as well.

Ooops.


#5

Actually scratch that, seems I’m still getting double records on the initial render.