redfin / react-server

:rocket: Blazing fast page load and seamless navigation.
https://react-server.io/
Apache License 2.0
3.89k stars 184 forks source link

handleRoute called twice, one on server, one on client #973

Open hong-duc opened 6 years ago

hong-duc commented 6 years ago

I have a page that fetch data when request to page

export default class HomePage {
  handleRoute(next) {
    this.title = SettingService.getSetting('title_trang_chu').then(result => {
      return result.value.value;
    });
    return next();
  }

  getElements() { ........

But the SettingService.getSetting get called twice and that make 2 request to the api server.

But this only happen if the getElements method return some elements, if it return empty array handleRoute will not be called on the client

Is this the expected behaviour ? Or I am using it wrong ? I just want to fetch data once when there is a request to a page and then wait for the result then render page

Thank you