rendrjs/rendr — pull request #360 by benjie (2014-04-17 09:35:46+00:00)
Title: Prevent rendering race conditions with slow APIs.

Imagine part of your API is responding slowly, or your user has a variable latency internet connection (perhaps 3G on a train...).

You have three pages: A, B and C; where B takes 2 seconds to load it's data from the API and the other two are relatively instant. You start at A, click B then click C (without waiting for B to load). The result is that you see A's content, then C's content, then a second later finally B's content. But now the browser is showing B's content but with C's URL in the address bar! *Argh!*

The code attached is a naive fix for this by counting requests (on the browser only) - if you've initiated a new page load before the old one completes then the old one will never render.

**WARNING**: this does not work around issues such as triggering `action:end` for the old request or anything like that. This isn't so much a pull request as some code to demonstrate a naive fix for the issue in order to start a discussion.

**NOTE**: I'm using rendr 0.5.0 from npm so if you've fixed this since then I apologise :)