vercel / vercel/next.js

Redirecting to a static page with a revalidation time after entering draft mode shows stale content

Open
#84,306 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Draft Mode Linking and Navigating Server Actions
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/next-draft-mode-with-revalidate-bug-9p7dtw

To Reproduce
  1. Start the application in production (pnpm build && pnpm start)
  2. Open Chrome devtools. Ensure caching is not disabled. Go to the cookies section in the Application tab.
  3. Toggle on draft mode by pressing the toggle button.
    • Observe that the beside text now says "enabled" and the __prerender_bypass cookie was set.
  4. Toggle off draft mode by pressing the toggle button again.
    • Observe that the beside text now say "disabled" and the __prerender_bypass cookie is gone.
  5. Toggle on draft mode again by pressing the toggle button.
    • Observe that the beside text still says "disabled", however the __prerender_bypass cookie was set.
    • Observe also that the second to last RSC request uses disk cache, rather than fetching fresh.
Current vs. Expected behavior

Current behavior:

  • Redirecting to a page with a custom revalidate config time causes stale content to show after entering draft mode.
    • In other words, it seems like Next isn't properly busting the cache before redirecting after entering draft mode if the RSC response has a stale-while-revalidate in its Cache-Control header.
  • It also seems like redirecting from a server function is erroneously performing a redundant navigation from the client.

https://github.com/user-attachments/assets/a69250f5-1f6b-4211-b8d0-b9a49ad08e95

Server Action Response Redundant Navigation Response
Image Image

Expected behavior:

  • Entering draft mode and redirecting should bust/skip the cache completely and use a fresh RSC response.
  • There should not be an additional navigation after the server function completes and returns the updated UI.
Provide environment information
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.5.4 // Latest available version is detected (15.5.4).
  eslint-config-next: N/A
  react: 19.1.1
  react-dom: 19.1.1
  typescript: 5.3.3
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Draft Mode, Server Actions, Linking and Navigating

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

next start (local), Vercel (Deployed)

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and run it with pnpm build && pnpm start. Trace draft mode, Server Action redirects, cache handling, and RSC navigation; done means entering draft mode consistently fetches fresh content without a redundant navigation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, react
Domain
backend, frontend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.