Testing for Race Conditions
You'll learn how to artificially slow down your network and rapidly change state to expose hidden race condition bugs in your data fetching code.
The Challenge of Reproducing Bugs
Race conditions in data fetching are notoriously hard to catch during normal development. When your network is fast and you click slowly, responses arrive in order and everything seems fine. The bug only appears when real users click quickly or have slow connections—situations that are hard to reproduce naturally.
Using Network Throttling
Modern browser DevTools let you artificially slow down your network. In Chrome DevTools:
- Open the Network tab
- Change the throttling dropdown from "No throttling" to "Slow 3G" or "Fast 3G"
This makes every request take several seconds, giving you time to trigger multiple requests before the first one completes—exactly the scenario where race conditions occur.
Rapid State Changes
With throttling enabled, quickly change the input or trigger that causes your fetch. For example, in a search box, type "a", then immediately "ab", then "abc". You should see multiple requests fire. Now watch which response updates your UI last. If it's not the most recent request, you've reproduced the race condition!
Verifying Your Fix
After implementing the ignore flag pattern, repeat the test:
- Enable network throttling
- Rapidly trigger multiple fetches
- Verify that only the last request updates your state
- Check that earlier responses are ignored even if they arrive later
This manual testing catches issues that might slip through in production.
Key Takeaway: Use browser network throttling plus rapid user interactions to reliably reproduce and verify fixes for race condition bugs before they reach your users.