[PR #369] [MERGED] fix: draftMode() must mark dynamic usage to prevent caching #517

Closed
opened 2026-05-06 13:08:30 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/369
Author: @NathanDrake2406
Created: 3/9/2026
Status: Merged
Merged: 3/9/2026
Merged by: @james-elicx

Base: mainHead: fix/draft-mode-dynamic-usage


📝 Commits (1)

  • 5bf7f39 fix: mark dynamic usage in draftMode() to prevent caching

📊 Changes

2 files changed (+25 additions, -0 deletions)

View changed files

📝 packages/vinext/src/shims/headers.ts (+1 -0)
📝 tests/nextjs-compat/draft-mode.test.ts (+24 -0)

📄 Description

Summary

  • draftMode() reads the __prerender_bypass cookie (request-specific data) but did not call markDynamicUsage(), unlike headers() and cookies()
  • This means a Server Component branching on draftMode().isEnabled could have its output cached by ISR, serving draft content to regular users or stale content to draft users
  • Added the missing markDynamicUsage() call and a test verifying the behavior

Test plan

  • New test: draftMode() marks dynamic usage so the render is uncacheable — calls draftMode() within a headers context and asserts consumeDynamicUsage() returns true
  • All existing draft-mode tests pass (8/8)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/369 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/9/2026 **Status:** ✅ Merged **Merged:** 3/9/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/draft-mode-dynamic-usage` --- ### 📝 Commits (1) - [`5bf7f39`](https://github.com/cloudflare/vinext/commit/5bf7f3970d0f93ec3bb7df886d164d7e1efe28b3) fix: mark dynamic usage in draftMode() to prevent caching ### 📊 Changes **2 files changed** (+25 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/shims/headers.ts` (+1 -0) 📝 `tests/nextjs-compat/draft-mode.test.ts` (+24 -0) </details> ### 📄 Description ## Summary - `draftMode()` reads the `__prerender_bypass` cookie (request-specific data) but did not call `markDynamicUsage()`, unlike `headers()` and `cookies()` - This means a Server Component branching on `draftMode().isEnabled` could have its output cached by ISR, serving draft content to regular users or stale content to draft users - Added the missing `markDynamicUsage()` call and a test verifying the behavior ## Test plan - [x] New test: `draftMode() marks dynamic usage so the render is uncacheable` — calls `draftMode()` within a headers context and asserts `consumeDynamicUsage()` returns `true` - [x] All existing draft-mode tests pass (8/8) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:30 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#517
No description provided.