Skip to content

Conversation

@maral
Copy link
Contributor

@maral maral commented Jul 1, 2025

What?

Fix misleading information in the docs about mixing cached and uncached fetch calls during dynamic rendering.

Why?

I followed the guide (using Next.js 15.3.2) and tried it out with this code:

  const joke = await fetch("https://api.chucknorris.io/jokes/random", {
    cache: "no-cache",
  });
  const jokeData = await joke.json();

  console.log("Fetched joke:", jokeData.value);

  const joke2 = await fetch(
    "https://api.chucknorris.io/jokes/random?category=dev"
  );
  const jokeData2 = await joke2.json();
  console.log("Fetched joke2:", jokeData2.value);

After building and starting the production server, when I refresh the page, both jokeData.value and jokeData2.value are different, uncached. If I want the other fetch to be cached, I need to explicitly enable caching, e.g.

  const joke = await fetch("https://api.chucknorris.io/jokes/random", {
    cache: "no-cache",
  });
  const jokeData = await joke.json();

  console.log("Fetched joke:", jokeData.value);

  const joke2 = await fetch(
    "https://api.chucknorris.io/jokes/random?category=dev",
    {
      cache: "force-cache",
    }
  );
  const jokeData2 = await joke2.json();
  console.log("Fetched joke2:", jokeData2.value);

This way the first fetch is not cached while the second one is.

How?

The previous version claimed:

Other fetch requests that do not opt out of caching will still be cached in the Data Cache.

But below in the guide, we can see this:

The default caching behavior of fetch (e.g., when the cache option is not specified) is equal to setting the cache option to no-store:

So the first citation is misleading - the fetch requests are not cached by default (with dynamic rendering - static rendering would cache the single call it into the output), so we actually need to explicitly enable caching to have them cached.

fix incorrect information in the docs
@ijjk ijjk added the Documentation Related to Next.js' official documentation. label Jul 1, 2025
@ijjk
Copy link
Member

ijjk commented Jul 1, 2025

Allow CI Workflow Run

  • approve CI run for commit: d7724dc

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

1 similar comment
@ijjk
Copy link
Member

ijjk commented Jul 1, 2025

Allow CI Workflow Run

  • approve CI run for commit: d7724dc

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@icyJoseph
Copy link
Collaborator

Hi,

Thanks for the contribution.

That's correct, when the default caching behavior of fetch changed - a few places in the docs got outdated.

@icyJoseph icyJoseph merged commit 5efef45 into vercel:canary Jul 2, 2025
59 checks passed
@maral maral deleted the patch-3 branch July 2, 2025 13:57
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Documentation Related to Next.js' official documentation. locked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants