denvned / isomorphic-relay-router

Adds server side rendering support to react-router-relay
BSD 2-Clause "Simplified" License
137 stars 26 forks source link

Client will have to wait infinitely if render() throws #43

Closed ghost closed 8 years ago

ghost commented 8 years ago

If anything inside render() throws, server will not respond to client making them wait infinitely. Example:

import IsomorphicRouter from 'isomorphic-relay-router';

app.get('/*', (req, res, next) => {
  match({routes, location: req.originalUrl}, (error, redirectLocation, renderProps) => {
    if (error) {
      next(error);
    } else if (redirectLocation) {
      res.redirect(302, redirectLocation.pathname + redirectLocation.search);
    } else if (renderProps) {
      IsomorphicRouter.prepareData(renderProps, networkLayer).then(render, next);
    } else {
      res.status(404).send('Not Found');
    }

    function render({data, props}) {
      throw new Error("Something failed");
    }
  });
});

Encountered this problem while trying to convert a react-relay component to isomorphic-relay-router.

denvned commented 8 years ago

See here: https://github.com/denvned/isomorphic-relay-router/issues/38#issuecomment-228018924 Sorry, I forgot to push the fix the first time it was reported, but did it now.