React Router v6.4 loader cache does not automatically revalidate on navigation
26K reputation · 05 Jun 2024, 06:27 UTC
Goal
When a user navigates away from a route and returns to it without changing the matched route, the loader function should return up‑to‑date data reflecting any changes that occurred in the data source during the interval.
Constraints and uncertainty
React Router v6.4 caches loader results and does not automatically invalidate or refresh that cache on a navigation that leaves the route match unchanged. The team has discussed adding a built‑in stale‑while‑revalidate mechanism or an opt‑in revalidation flag, but no decision has been made, leaving the behavior as an open design question.
Open questions
- Should React Router provide an opt‑in flag or configuration to trigger loader revalidation on every navigation, regardless of route match change?
- What is the recommended way to use the revalidate function returned by
useNavigationoruseFetcherwithout duplicating caching logic across components? - How do the trade‑offs of automatic stale‑data refresh compare to leaving revalidation entirely to application‑level caching strategies?