Skip to content

Instantly share code, notes, and snippets.

@StevenLangbroek
Last active February 18, 2016 08:34
Show Gist options
  • Save StevenLangbroek/fc5ab21ac4be4373dc25 to your computer and use it in GitHub Desktop.
Save StevenLangbroek/fc5ab21ac4be4373dc25 to your computer and use it in GitHub Desktop.
Ok, so here's what happened. (Pseudo-code ahead)
const app = express();
app.use((req, res) => {
// Match routes from React Router
match({ history, routes, location: req.originalUrl }, (err, redirectLocation, renderProps) => {
Promise.all(getFetchFunctions(renderProps).map(fetchThem)).then(() => {
ReactDOM.renderToString(
<Provider>
<Router /> // You get the idea right? All fetches have been ran through the store, and you render out.
</Provider>
);
});
})
})

So, one of my fetchers (for user data) was failing, which was fine. I had a catch in place, and my other requests came through the store. The API server responded to all requests, and the logging information I added to my reducers showed me that the rest of my requests were being merged into my store.

What happened on actual production server, but not locally, is that the Promise.all resolved as soon as the request rejected, started rendering out my app, but with the store in the state it was before one of my other requests was processed by its reducer. So all my logging information showed me that everything was working fine (request reaching API, reducer running), while in practice it never reached the state I expected the UI to be in.

This exposed a huge flaw in my logic (the request I was fine with failing should never be made if it's gonna fail, which I wasn't guarding against), but it caught me off guard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment