#next.js 15 fetch cache

1 messages · Page 1 of 1 (latest)

molten carbon
#

Does Next.js 15 fetch no-store only work in Server Components? Or does it also apply when executing

static wedgeBOT
#

Hi @molten carbon. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

In Next.js 15, fetch requests are no longer cached by default [Upgrading to version 15]. The behavior of cache: 'no-store' depends on whether it is executed on the server or the client:

Server-Side Execution (Server Components & Route Handlers)

On the server, cache: 'no-store' interacts with the Next.js Data Cache. It ensures that the resource is fetched from the remote server on every request, bypassing the persistent Data Cache [Fetch API Reference].

However, there is a nuance regarding Request Memoization:

  • Server Components: Even with no-store, Next.js (via React) will still memoize GET requests within the same render pass. If you call the same fetch with no-store twice in the same React component tree, the second call will return the memoized result from the first call to avoid duplicate network requests during a single render [Request Memoization; Github Issue 73589].
  • Route Handlers: Request memoization does not apply to Route Handlers because they are not part of the React component tree [Request Memoization].

Client-Side Execution

In the browser, the cache option in fetch follows the standard Web API behavior and indicates how the request interacts with the browser's HTTP cache, rather than the Next.js Data Cache [Data Cache; Fetch API Reference].

#

Key Differences in Next.js 15

  • Default Behavior: Unlike previous versions, fetch requests in Next.js 15 are not automatically cached. You must explicitly use cache: 'force-cache' to opt into the Data Cache [Upgrading to version 15].
  • Development (HMR): In local development, Next.js may still cache no-store responses across Hot Module Replacement (HMR) refreshes to improve performance, unless you disable serverComponentsHmrCache in your config [Server Components HMR Cache; Fetch Troubleshooting].

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: