Expired auth token throws into React 18 Suspense ErrorBoundary with no cache invalidation or retry API
0 reputation · 24 Mar 2022, 08:12 UTC
React 18 documents Suspense-enabled data fetching as experimental. When a fetch of a protected resource rejects because an authentication token has expired, the thrown error propagates to the nearest ErrorBoundary, and Suspense itself provides no retry or fallback mechanism.
The Suspense cache is keyed by the data fetching function, and the public API exposes no method to manually invalidate or refresh a cached entry. Suspense does not distinguish transient failures such as token expiry from permanent errors, and no built-in token refresh flow exists, so authentication recovery is left entirely to custom wrapper logic.
The design goal is a protected-data view that can recover from an expired credential without unmounting the whole tree or serving stale cached data after the token is renewed.
How should token expiry be modeled inside an ErrorBoundary so that a refresh-and-refetch cycle is possible? What invalidation strategy fits a cache that exposes no manual invalidation API? Should a library such as @tanstack/react-query own this flow instead of core Suspense?