Strange behavior with findAll and peekAll in emberjs 4.12


I am in the process of upgrading my app from emberjs 3.28 to 4.12. Besides all the deprecations, I have another problem that is not present with 4.11.

Right after login I do the following in my index route:

@inject store;
async model() {
  let c1 = await'client', 'valid id');
  let clientsFind = await'client');
  let c2 ='client', 'another valid id');
  let clientsPeek ='client');
  console.log('index.model', {c1, clientsFind, c2, clientsPeek});

c1 and c2 contain the correct model, but clientsFind and clientsPeek are an empty array. In the developer console, I can see the /clients query, which returns ALL the data.

What’s even stranger is that when I reload the page, findAll and peekAll suddenly return the array with all the data. But without the reload findAll also returns an empty array at another route.

As I said, with 4.11 there is no problem. So what is happing here?

I don’t know if it matters, for login I use ember-simple-auth and ember-simple-auth-token.

Thanks for your help

I just checked it with the Ember extension in Chrome and Firefox: After login I have 6 model types with 0 data. After refresh I have 7 model types with a lot of data. But despite 0 data, peekRecord returns a model?

I encounter somewhat similar issue when trying to get my head around the new ember-data. I’m still not sure and might just stick to the ‘old way’ for now.

Right now I don’t care about the new request manager at all. I just want to get my data without reloading the page (and get rid of all the deprecations, but I think that’s another topic).

This sounds like an Ember Data bug to me as your code is pretty straightforward and the request is being made the same way in both cases (if i’m understanding that right). In the first case it’s just not being serialized into the store/response array properly. If you haven’t already I’d look at ember data issues and considering opening one. A minimal reproduction would be ideal if you can duplicate this.

Other things you could check off the top of my head:

  • make sure you only have one version of ember data in your package lock
  • do you have any code anywhere that’s clearing the store or unloading records?
  • do you have a custom serializer?

If it were me I’d try and step through the model hook in the debugger, and also step through the ember data serialization guts to see what’s going on and where it’s failing.

I suspect you need to update to 4.12.2 which had a fix for unloadAll causing change notifications to be lost

1 Like

Thanks that did it. Some problems get solved by merely waiting. :grin: