ember-fastboot / ember-cli-fastboot

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

Abort content replace if error happens on model loading #847

Open mydea opened 3 years ago

mydea commented 3 years ago

We use fastboot for a content-focused website which is powered by a wordpress instance. Whenever content is changed we run a static build with prember & deploy the application - all good so far.

Now I noticed that if wordpress goes down (for whatever reason), and somebody visits a page, the pre-rendered page will be shown correctly, but once ember is loaded & it tries to hit the API and fails, it replaces the body with the error message.

Is there a way to basically say:

"If one of these errors is encountered, skip doing anything and just leave the HTML as it is"? Because it would be much better to just show the static page in such a scenario.

I hope I could explain my question properly :sweat_smile:

I am using EXPERIMENTAL_RENDER_MODE_SERIALIZE=true, if that is relevant.

One "solution" I could think of is to return a never-resolving promise from the model hook in such a case instead of throwing an error, as I've observed that while the model hooks are pending it will not replace the content. Would that be a "good" solution or is there a better way to do this? E.g. something like that feels rather hacky:

export default class PageRoute extends Route {
  @service fastboot;

  async model(params) {
    try {
      return await this.store.findRecord('page', params.id);
    } catch(error) {
      if (!this.fastboot.isFastBoot) {
        await new Promise();
      }
    }
  }
}