A use cache function's key is built from its build ID, its identity and its arguments. Its output is reused for every later call with the same key, by any user, and it may be computed during next build, when no request exists. If the body could call cookies() or headers(), the result would depend on something that isn't in the key: user A's cookie would decide what user B sees. So Next.js forbids it. cookies(), headers(), searchParams and connection() all throw inside a cached scope, and the rule follows the call stack: a helper that reads headers() fails the same way when a cached function calls it. draftMode().isEnabled is the documented exception.
The fix is to move the read up one level and pass the value down:
- An uncached component reads
cookies(). Under Cache Components it must sit inside<Suspense>, so it becomes a request-time hole in the static shell. - It extracts only what the cached work depends on (a currency, a locale, a boolean) and calls the cached function with that value.
- The value is now an argument, so it is part of the key: one entry per currency, not one shared answer.
Pass the smallest value that decides the output. A session ID makes one entry per user; a currency gives a handful shared by everyone. Pass the resolved value, never the cookies() promise itself, which hangs the build.
When refactoring isn't practical, or per-user data must stay out of shared server caches, use cache: private allows request APIs at the cost of no server-side reuse across requests.