Loading...
const getPost = cache((id) => fetch(`/api/posts/${id}`));
async function Post({ id }) {
const res = await getPost(id);
return <Article data={await res.json()} />;
}const getPost = cache((id) => fetch(`/api/posts/${id}`, { signal: cacheSignal() }));
async function Post({ id }) {
const res = await getPost(id);
return <Article data={await res.json()} />;
}The fetch is aborted when React no longer needs the result, so an abandoned render does not keep requests running.
cacheSignal() in a Client Component and passing its null result as if it were a signal.cacheSignal() is called only in Server Components, not in Client Components.fetch or another API that accepts an AbortSignal.null return, which happens when it runs outside of rendering.When React finishes rendering, when the render is aborted, or when it fails. After that, results of cached work are no longer used.
It returns null outside of a server render, for example in a Client Component or in code that runs after rendering.