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

Ember Data still makes request #19

Open
deanmraz opened this issue Sep 14, 2018 · 4 comments
Open

Ember Data still makes request #19

deanmraz opened this issue Sep 14, 2018 · 4 comments

Comments

@deanmraz
Copy link

Issue

  • I'm still seeing a network request

Expected

  • Retrieve the data from shoebox

Steps

  1. I created a demo here https://github.com/deanmraz/ember-data-shoebox-demo
  2. yarn install
  3. ember serve
  4. Visit localhost:4200 with network tab open

Observe

  1. articles model gets requested. screenshot 2018-09-14 11 45 30
  2. <script type="fastboot/shoebox" id="shoebox-ember-data-store"> in html looks correct.

screenshot 2018-09-14 11 45 41

@MartinMalinda
Copy link
Contributor

MartinMalinda commented Sep 14, 2018

Is it a blocking promise or a background reload? Is the issue also present with shouldBackgroundReloadAll being set to false?

https://www.emberjs.com/api/ember-data/3.4/classes/DS.Adapter/methods/shouldBackgroundReloadAll?anchor=shouldBackgroundReloadAll

Overall this is an interesting problem. Background reload does not make much sense on first initial load, but is probably still desired on normal in-app transitions. So disabling it on first route visit might make sense, but I'm not aware of any super easy way of doing it.

I guess this also might not be a background reload problem and this is caused because Ember Data cannot tell findAll has previously been done just by retrieving models from shoebox.

@deanmraz
Copy link
Author

deanmraz commented Sep 14, 2018 via email

@deanmraz
Copy link
Author

@MartinMalinda that was it, does it make sense to throw this in the README.md?

@deanmraz
Copy link
Author

Wanted to make sure I record this, because came back to the same issue in another project.

peekAll first to grab the cache records, but if none exist then run the query. For some reason shouldBackgroundReloadAll didn't work in the latest ember version 3.7. Also more control with this approach.

import Route from '@ember/routing/route';

export default Route.extend({
  model() {
    const collection = this.store.peekAll('article');
    if (collection.length === 0) {
      return this.store.query('article', {
        feed: 'latest',
      });
    }
    return collection;
  }
});

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

No branches or pull requests

2 participants