Skip to main content

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:
Each submission triggers its own revalidation, and they can overlap.

Stale Data Prevention

React Router prevents stale data from appearing:
If submission 2’s revalidation completes before submission 1’s, the data from submission 1 is discarded as stale. The rule: Data from requests that started later takes precedence.

Concurrent Loaders

Loaders run in parallel by default:

Sequential Loading

Use data strategy for sequential loading:
Automatic concurrency management for search:
How it works:
  1. User types “New”
  2. Request 1: ?q=N
  3. User types “e” (before request 1 completes)
  4. Request 1 cancelled, Request 2: ?q=Ne
  5. User types “w”
  6. Request 2 cancelled, Request 3: ?q=New
  7. 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

  1. Trust automatic cancellation: Don’t manually track requests
  2. Use fetchers for concurrent operations: Navigation is singleton
  3. Debounce rapid inputs: Reduce server load
  4. Show loading states: Indicate pending requests
  5. Handle optimistic failures: Revert on error

Monitoring Concurrency

Track concurrent request metrics: