ReactSSRCasts icon indicating copy to clipboard operation
ReactSSRCasts copied to clipboard

AZ Does it mean whenever client has a get request, server will iterate every route and fire API call for each one to fill Redux store?

Open ArtixZ opened this issue 6 years ago • 0 comments

app.get('*', (req, res) => {
  const store = createStore(req);

  const promises = matchRoutes(Routes, req.path)
    .map(({ route }) => {
      return route.loadData ? route.loadData(store) : null;
    })
    .map(promise => {
      if (promise) {
        return new Promise((resolve, reject) => {
          promise.then(resolve).catch(resolve);
        });
      }
    });

  Promise.all(promises).then(() => {
    const context = {};
    const content = renderer(req, store, context);

    if (context.url) {
      return res.redirect(301, context.url);
    }
    if (context.notFound) {
      res.status(404);
    }

    res.send(content);
  });
});

Looking at this part of code in index.js, this method is bind to every get request.

Does it mean there is a lot of overhead when user navigates frequently between screens?

Same issue raised here: https://www.udemy.com/server-side-rendering-with-react-and-redux/learn/v4/questions/4896838

ArtixZ avatar Aug 09 '18 22:08 ArtixZ