ember-fastboot / ember-cli-fastboot

Server-side rendering for Ember.js apps
http://ember-fastboot.com/
MIT License
851 stars 160 forks source link

Duplicate first app load #607

Open erzzo opened 6 years ago

erzzo commented 6 years ago

I'm experiencing a strange behavior and I'm not sure if it's a bug. When I start my app it always fires two api requests. It looks like the app loads and then it reloads the second time.

I've created a new ember project and the same happens. Just a route call:

export default Route.extend({
    model() {
        return fetch('http://localhost:3333/me')
    }
});

inspector: image

and the server: image

When it loads, all other api calls are fired only once and it only happens when fastboot is enabled.

My packages:

    "broccoli-asset-rev": "^2.4.5",
    "ember-ajax": "^3.1.0",
    "ember-cli": "^3.3.0",
    "ember-cli-app-version": "^3.0.0",
    "ember-cli-babel": "^6.6.0",
    "ember-cli-dependency-checker": "^2.0.0",
    "ember-cli-eslint": "^4.0.0",
    "ember-cli-fastboot": "^1.1.4-beta.1",
    "ember-cli-htmlbars": "^2.0.1",
    "ember-cli-htmlbars-inline-precompile": "^1.0.0",
    "ember-cli-inject-live-reload": "^1.4.1",
    "ember-cli-qunit": "^4.0.0",
    "ember-cli-shims": "^1.1.0",
    "ember-cli-sri": "^2.1.0",
    "ember-cli-uglify": "^2.0.0",
    "ember-data": "^2.16.4",
    "ember-export-application-global": "^2.0.0",
    "ember-fetch": "^5.1.1",
    "ember-load-initializers": "^1.0.0",
    "ember-resolver": "^4.0.0",
    "ember-source": "~2.16.0",
    "ember-welcome-page": "^3.0.0",
    "loader.js": "^4.2.3"

How can I prevent this? I'm making some token invalidation and it is screwing things up.

koslib commented 6 years ago

I have the exact same issue, my inspection so far presumes that it's a bug. When I disable fastboot and run with ?fastboot=false, it works normally again.

Redsandro commented 5 years ago

The model is fetched by ember-fastboot on the server side. Once the app is executing client-side, it needs the data, otherwise any and all functionality other than just template displays using the model would not work. So the client fetches again.

One way to prevent this is using some kind of cache like https://github.com/cardstack/ember-data-fastboot. But I'd like to see a more mainstream solution. I've asked a question on SO: https://stackoverflow.com/questions/55523523/models-in-ember-fastboot-loaded-twice