Concurrency Patterns
React Router automatically manages concurrent requests, ensuring your UI stays responsive and displays the most recent data.Browser Behavior
React Router mirrors browser behavior for navigation: Link Clicks: When you click a link and then click another before the first loads, the browser cancels the first request. Form Submissions: When you submit a form and then submit another, the browser cancels the first submission. React Router implements the same behavior for client-side navigation.Automatic Cancellation
Interrupted Navigation
Requests are automatically cancelled when interrupted:Interrupted Submissions
Form submissions cancel previous submissions:Concurrent Fetchers
Unlike navigation, fetchers can run simultaneously:Revalidation
After any action completes, React Router revalidates all page data:Stale Data Prevention
React Router prevents stale data from appearing:Concurrent Loaders
Loaders run in parallel by default:Sequential Loading
Use data strategy for sequential loading:Type-Ahead Search
Automatic concurrency management for search:- User types “New”
- Request 1:
?q=N - User types “e” (before request 1 completes)
- Request 1 cancelled, Request 2:
?q=Ne - User types “w”
- Request 2 cancelled, Request 3:
?q=New - Only Request 3’s results are shown
Debouncing
Reduce request frequency:Throttling
Limit request rate:Race Condition Prevention
Fetchers prevent UI bugs from race conditions:Request Coordination
Coordinate multiple dependent requests:Batch Requests
Batch multiple requests into one:Optimistic UI
Show immediate feedback during concurrent requests:Polling
Poll for updates without blocking UI:Request Deduplication
Prevent duplicate concurrent requests:Best Practices
- Trust automatic cancellation: Don’t manually track requests
- Use fetchers for concurrent operations: Navigation is singleton
- Debounce rapid inputs: Reduce server load
- Show loading states: Indicate pending requests
- Handle optimistic failures: Revert on error