vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.02k stars 26.7k forks source link

Draft mode cookie no being set on edge runtime #69449

Open otoxiep95 opened 2 weeks ago

otoxiep95 commented 2 weeks ago

Link to the code that reproduces this issue

https://github.com/otoxiep95/next-draft-edge-issue-reproduction

To Reproduce

  1. Clone the repo
  2. Run npm install
  3. Run npm run dev
  4. Open the browser at http://localhost:3000/api
  5. Open and edit app/api/route.ts and remove export const runtime = "edge";
  6. Retest the issue

Current vs. Expected behavior

Cookie header is set, but the value it wrong and results in draft mode not being enabled.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 20.17.0
  npm: 10.8.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.0.0-canary.134 // Latest available version is detected (15.0.0-canary.134).
  eslint-config-next: N/A
  react: 19.0.0-rc-7771d3a7-20240827
  react-dom: 19.0.0-rc-7771d3a7-20240827
  typescript: 5.3.3
Next.js Config:
  output: N/A

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

Runtime

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

next dev (local), Vercel (Deployed)

Additional context

Screenshot 2024-08-29 at 11 24 16 Screenshot 2024-08-29 at 11 24 28 Screenshot 2024-08-29 at 11 24 56

abhi12299 commented 2 weeks ago

I think this is intentional. Have a look at this PR: https://github.com/vercel/next.js/pull/67779 where they assume the draft mode is active when the env is development and the cookie value is development-id when running in edge runtime.

Quoting the author of the PR:

So we do a fallback check for dev mode if the cookie is present and preview id is development-id then we still treat it as draft mode is enabled.

markomitranic commented 2 weeks ago

In my testing with the repository @otoxiep95 has opened above, this is not true - sure, the cookie gets set with this static value, but:

  1. this differs from behaviour on the same dev server when using nodejs, and differs from running a local or docker server, but is the same as Vercel - all of which tells me that it is in no way intended.
  2. it simply doesn't turn on the preview mode. The isDraft function of Next.JS evaluates to false.

Thank you for posting the link to the related PR @abhi12299 , sounds like it was recently merged so perhaps it is an issue that will be solved through the v15 rc