Skip to content

fix(cache): bypass fetch cache in draft mode - #2786

Open
NathanDrake2406 wants to merge 3 commits into
cloudflare:mainfrom
NathanDrake2406:nathan/fix-draft-mode-fetch-cache
Open

fix(cache): bypass fetch cache in draft mode#2786
NathanDrake2406 wants to merge 3 commits into
cloudflare:mainfrom
NathanDrake2406:nathan/fix-draft-mode-fetch-cache

Conversation

@NathanDrake2406

@NathanDrake2406 NathanDrake2406 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Overview

Fix draft-mode data isolation for both App Router and Pages Router fetches. Draft renders now bypass persistent fetch-cache reads and writes while retaining render-scoped memoization, so editors receive current origin data without changing published cache entries.

What changed

  • Added the draft guard to createPatchedFetch.
  • Route draft fetches through dedupeFetch so repeated GET and HEAD requests remain memoized within a render.
  • Record draft fetches as dynamic dependencies for App Router layout-reuse observation.
  • Propagate Pages preview state through the unified request context in both production and dev handlers.
  • Build dedupe keys from effective GET and HEAD Requests so init header overrides cannot share a response across variants.
  • Preserve existing pass-through behavior for POST and consumed-body Requests.

Behavior

Scenario Result
Normal cached fetch Existing shared cache behavior is unchanged
App Router draft fetch Fresh origin fetch, no persistent read or write, render-scoped dedupe retained
Pages Router preview fetch Fresh origin fetch in both production and dev
Public fetch after draft render Existing published entry remains intact
Draft layout probe Fetch dependency is recorded as dynamic, preventing unsafe layout reuse

Validation

  • vp test run tests/fetch-cache.test.ts: 129 passed
  • vp test run tests/pages-page-handler.test.ts: 37 passed
  • vp test run tests/pages-router.test.ts: 378 passed
  • App layout, page dispatch, execution, and render tests: 174 passed
  • vp test run tests/shims.test.ts: 1,278 passed
  • vp check: 1,175 files checked with no warnings or errors
  • vp run vinext#build: passed
  • Required PR CI and performance checks: green

References

Draft renders currently read and write shared fetch entries, so a fetch with next.revalidate can return published data to editors and publish draft data to later public requests.\n\nForward draft-mode fetches directly to the original fetch, matching Next.js and keeping draft responses out of the shared cache. Add regression coverage for both the cache read and write paths.
@NathanDrake2406

Copy link
Copy Markdown
Contributor Author

@codex review

@pkg-pr-new

pkg-pr-new Bot commented Aug 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vinext/cloudflare@2786
npm i https://pkg.pr.new/create-vinext-app@2786
npm i https://pkg.pr.new/@vinext/types@2786
npm i https://pkg.pr.new/vinext@2786

commit: f9639c3

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f54443eaed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/vinext/src/shims/fetch-cache.ts Outdated
Comment thread packages/vinext/src/shims/fetch-cache.ts Outdated
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared f9639c3 against base ced0881 using alternating same-runner rounds. Next.js was unchanged and skipped.

0 improved · 0 regressed · 6 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 134.6 KB 134.6 KB ⚫ +0.0%
Client entry size (gzip) vinext 122.1 KB 122.1 KB ⚫ +0.0%
Dev server cold start vinext 2.29 s 2.29 s ⚫ -0.1%
Production build time vinext 2.36 s 2.36 s ⚫ +0.1%
RSC entry closure size (gzip) vinext 112.4 KB 112.4 KB ⚫ +0.0%
Server bundle size (gzip) vinext 189.9 KB 189.9 KB ⚫ +0.0%

View detailed results and traces

🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head

@NathanDrake2406
NathanDrake2406 marked this pull request as ready for review August 1, 2026 05:50
Pages Router preview requests now publish their decoded preview state to the unified request context in both development and production. Draft fetches continue through request-scoped deduplication while bypassing the shared data cache, with production and dev regressions covering both behaviors.
@NathanDrake2406
NathanDrake2406 marked this pull request as draft August 1, 2026 06:11
@NathanDrake2406

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 966e89ade7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/vinext/src/shims/fetch-cache.ts
Comment thread packages/vinext/src/shims/fetch-cache.ts
Build dedupe keys from effective GET and HEAD requests so Request init overrides cannot share a response across variants, while preserving body-bearing pass-through behavior. Record draft fetches as dynamic layout dependencies so App Router reuse cannot skip fresh data. Add regressions for both review findings.
@NathanDrake2406

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: f9639c3156

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@NathanDrake2406
NathanDrake2406 marked this pull request as ready for review August 1, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant