Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request cookies not available in draft mode #76200

Closed
joostmeijles opened this issue Feb 19, 2025 · 4 comments
Closed

Request cookies not available in draft mode #76200

joostmeijles opened this issue Feb 19, 2025 · 4 comments
Labels
Draft Mode Related to Draft Mode.

Comments

@joostmeijles
Copy link
Contributor

Link to the code that reproduces this issue

https://github.com/joostmeijles/no-cookies-in-draftmode

To Reproduce

  1. Start the application npm run dev
  2. Enable draft mode by opening: http://localhost:3000/api/enable
  3. Browse to http://localhost:3000/
  4. Observe in the developer console that the request cookie map is empty: RequestCookies { _parsed: Map(0) {}, _headers: Headers {} }

Current vs. Expected behavior

Expected to have request cookies available when draft mode is enabled.

Note that removing export const dynamic = 'force-static'; from https://github.com/joostmeijles/no-cookies-in-draftmode/blob/adb9d72554d42bf7f9d28d7b82c75104453265ca/app/page.tsx#L3 solves the issue, but this is not feasible as pages require ISR.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Enterprise
  Available memory (MB): 32472
  Available CPU cores: 16
Binaries:
  Node: 22.13.1
  npm: 10.9.2
  Yarn: 1.22.19
  pnpm: 9.15.5
Relevant Packages:
  next: 15.2.0-canary.65 // Latest available version is detected (15.2.0-canary.65).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next dev (local), Vercel (Deployed), next start (local)

Additional context

Inspecting request cookies in draft mode is necessary for properly functioning of the previewing in a CMS.

@joostmeijles
Copy link
Contributor Author

Found a (temporary) workaround by replacing export const dynamic = 'force-static'; with export const revalidate = 60000;

@samcx samcx added the Draft Mode Related to Draft Mode. label Feb 20, 2025
@samcx
Copy link
Member

samcx commented Feb 20, 2025

@joostmeijles Thank you for submitting an issue!

We are taking a look—

@samcx
Copy link
Member

samcx commented Feb 20, 2025

@joostmeijles This is expected with force-static.

Force static rendering and cache the data of a layout or page by forcing cookies, headers() and useSearchParams() to return empty values.

Since you want to use ISR on the page, it would be the correct option to use revalidate (not a workaround).

@samcx samcx closed this as completed Feb 20, 2025
@joostmeijles
Copy link
Contributor Author

@samcx please note that this workaround was provided by the NextJS team. Without export const dynamic = 'force-static' the page was always rendered on-demand (the Vercel-Cache header is always MISS).

This is also stated on the NextJS documentation page (https://nextjs.org/docs/app/api-reference/functions/generate-static-params):

You must return an empty array from generateStaticParams or utilize export const dynamic = 'force-static' in order to revalidate (ISR) paths at runtime.

Is this behavior now changed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Draft Mode Related to Draft Mode.
Projects
None yet
Development

No branches or pull requests

2 participants