Skip to content

fix(use-cache): do not warn unexpected cache miss in draft mode (#100680) - #100697

Draft
wasim-builds wants to merge 1 commit into
vercel:canaryfrom
wasim-builds:fix/issue-100680-draft-mode-cache-miss
Draft

wasim-builds wants to merge 1 commit into
vercel:canaryfrom
wasim-builds:fix/issue-100680-draft-mode-cache-miss

Conversation

@wasim-builds

Copy link
Copy Markdown
Contributor

What?

Prevents logging UnexpectedCacheMissError ("Unexpected cache miss after cache warming phase during prerendering") when draft mode is enabled. Also ensures Lockfile.tryAcquire safely handles native SWC bindings that return the native lockfile directly.

Why?

When draft mode is active on a route using Partial Prefetching and Cache Components (cacheComponents: true / PPR), saveToResumeDataCache in use-cache-wrapper.ts deliberately skips saving entries to the Resume Data Cache:

// When draft mode is enabled, we must not save the cache entry.
if (!workStore.isDraftMode) {
  const savedCacheResult = saveToResumeDataCache(...)

During the subsequent prerender pass (workUnitStore.type === 'prerender-runtime', !cacheSignal), the cache lookup in resumeDataCache naturally misses because it was intentionally omitted in the warming phase. use-cache-wrapper.ts then logged UnexpectedCacheMissError assuming the cache miss was caused by non-deterministic arguments, producing false warning noise for every CMS preview and draft mode request (issue #100680).

How?

  1. In packages/next/src/server/use-cache/use-cache-wrapper.ts, guard the console.warn(new UnexpectedCacheMissError(workStore.route)) call with if (!workStore.isDraftMode). The hanging promise continues to be returned so the function becomes a dynamic hole evaluated during the dynamic rendering pass.
  2. In packages/next/src/build/lockfile.ts, normalize bindings.lockfileTryAcquireSync output so both the new structured LockfileResult and pre-compiled native bindings returning raw external lockfiles are handled without throwing TypeError: Cannot read properties of null (reading 'type').
  3. Added a test case to test/production/app-dir/use-cache-non-deterministic-args verifying that requests with draft mode enabled resolve cached values without logging cache miss warnings.

Fixes #100680

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache Components: draft mode logs "Unexpected cache miss after cache warming phase" for deterministic keys (partialPrefetching)

1 participant