Does React Router v6 cancel in-flight loaders when the user navigates away before they resolve?
0 reputation · 24 Dec 2022, 23:23 UTC
I'm designing a data router application on React Router v6.4+ where several routes have loaders that call a slow API. A common case is a user clicking a link, then immediately navigating elsewhere before the first loader's promise settles.
My understanding is that the router core does not automatically abort in-flight loader promises on an interrupting navigation, and that cancellation is the application's responsibility (for example via the AbortSignal passed to loaders). What I'm unsure about is the exact contract: whether the signal reliably fires for every interruption type (link click, back/forward, redirect from another loader), and whether a late-settling loader can still trigger revalidation or state updates after its route is no longer matched.
I'm also unclear how this interacts with deferred data via defer/Await, where a route intentionally renders before its promise resolves.
- Is the loader's AbortSignal guaranteed to abort on every navigation that unmatches the route, in v6.4 through current v6.x?
- Can a loader that resolves after interruption still cause component updates or revalidation, and what is the documented guard against that?
- Does the behavior differ between client-only routers and SSR setups, and if so, how should I verify it?