Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
Allow dynamic APIs (`cookies()`, `headers()`) inside `"use cache"` when Draft Mode is enabled | GoodFirstPicks

Allow dynamic APIs (`cookies()`, `headers()`) inside `"use cache"` when Draft Mode is enabled

vercel/next.js 14 comments 1mo ago
View on GitHub
mediumopenScope: somewhat clearSkill match: maybeNext.jsTypeScriptReact

Why this is a good first issue

The issue requests relaxing cache restrictions during Draft Mode but involves core caching logic.

AI Summary

The issue requests allowing dynamic APIs like cookies() in cache scopes during Draft Mode, arguing cache is already bypassed. This requires modifying cache behavior validation while preserving Draft Mode's dynamic rendering guarantees. The main challenge is ensuring this change doesn't introduce caching edge cases or break existing Draft Mode assumptions.

Issue Description

Link to the code that reproduces this issue

https://github.com/angeloashmore/cache-components-draft-mode-dynamic-apis

To Reproduce

  1. Visit http://localhost:3000/ — page renders without cookies()
  2. Visit http://localhost:3000/api/draft — enables Draft Mode
  3. Visit http://localhost:3000/ — page renders with cookies() and throws

Current vs. Expected behavior

Current behavior:

When Draft Mode is enabled and I try to call cookies() inside a "use cache" function, Next.js throws an error:

Error: Route / used `cookies()` inside "use cache". Accessing Dynamic data
sources inside a cache scope is not supported. If you need this data inside a
cached function use `cookies()` outside of the cached function and pass the
required dynamic data in as an argument. See more info here:
https://nextjs.org/docs/messages/next-request-in-use-cache

This error occurs even though Draft Mode is enabled, which means the cache is already being bypassed (as fixed in #76581 / PR #77141).

Expected behavior:

When Draft Mode is enabled, dynamic APIs like cookies() and headers() should be allowed inside "use cache" functions, since:

  1. The cache is already bypassed — PR #77141 correctly skips cache reads and writes when Draft Mode is enabled
  2. Draft Mode inherently requires dynamic behavior — The whole point of Draft Mode is to render fresh, request-specific content
  3. This was the previous behavior — With the fetch cache, Draft Mode allowed reading cookies to pass preview tokens to CMS APIs
  4. draftMode().isEnabled is already allowed — As noted in PR #73324, draftMode().isEnabled is permitted inside "use cache" because "when it's on, it switches everything to dynamic rendering anyway, so that prerender/cache entry is ignored." The same logic should apply to other dynamic APIs.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.1.0: Mon O

GitHub Labels

linear: nextCache ComponentsDraft ModeCookiesHeaders

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!

Risk Flags

  • cache behavior changes
  • draft mode edge cases
Loading labels...

Details

Points10 pts
Difficultymedium
Scopesomewhat clear
Skill Matchmaybe
Test Focusedno