Abort stale server fetches with cacheSignal
Pass React cacheSignal to a Server Component fetch so pending work can stop when its render ends.
A Server Component is waiting for a summary from an upstream service. If the framework cancels the render while that call is still in flight, the fetch needs a signal to know it can stop. React exposes the lifetime of the render's cache through cacheSignal().
Give fetch the render's signal
In an app that supports React 19.2 Server Components, create a cached helper at module scope. Call it from a Server Component with a server-configured summary endpoint as url.
import { cache, cacheSignal } from 'react'
export const getSummary = cache(async (url) => {
const signal = cacheSignal()
const response = await fetch(url, { signal })
if (!response.ok) {
throw new Error('Summary request failed: ' + response.status)
}
return response.text()
})
export async function Summary({ url }) {
return await getSummary(url)
}On a normal render, the component displays the response text. If React aborts the render before the answer arrives, the signal cancels the pending fetch.
Call the helper with the same URL from two Server Components in the same render and they can share the result. The URL is the argument to the cached function. The function gets the current signal inside its body, at the point where it starts the request.
Capture the signal before the work starts
The signal aborts when React finishes, cancels, or fails the render. That is the cache lifetime described in the cacheSignal reference. A response body you're still reading can abort too, so keep the signal attached to the request that produced it.
If you move the fetch call to module scope, it can start before React renders a component. There is no current cache lifetime there, so cacheSignal() returns null. Keep the cached helper at module scope and the call to it inside the render.
Check cancellation separately from failure
Try a slow endpoint in a development environment, then cancel the render through the framework's server rendering integration. Look at the upstream request or log the captured signal's aborted property when the fetch fails. The goal is to see that the render stopped waiting and that the pending request received the same cancellation.
An HTTP error from a completed fetch follows the explicit status check in the example. Let that error reach the framework's error handling. If you log failed requests inside the helper, use the signal you captured at the start to distinguish a render abort from a request that failed while the render still needed it.