Skip to content

fix(cache): skip env-requiring cache adapters when no env is supplied - #3330

Open
Divkix wants to merge 1 commit into
cloudflare:mainfrom
Divkix:issue-3132
Open

Divkix wants to merge 1 commit into
cloudflare:mainfrom
Divkix:issue-3132

Conversation

@Divkix

@Divkix Divkix commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #3132

Summary

  • Add a requiresEnv flag to CacheAdapterDescriptor. The generated virtual:vinext-cache-adapters registrar emits that slot's registration inside if (env != null) { ... }, so a runtime that supplies no env skips it silently instead of invoking a factory that cannot construct and warning about it.
  • kvDataAdapter() sets requiresEnv: true, so Node runs (vinext build prerender, vinext start, Node dev) keep the default in-memory handler with no warning about a VINEXT_KV_CACHE binding that cannot exist off the Workers runtime.
  • Behaviour is unchanged where it matters: Workers callers always pass env, so registration happens exactly as before; an env-present caller whose binding is genuinely missing still logs the existing warning; adapters that never opt in keep the previous attempt-and-warn behaviour.
  • One docs line in docs/caching.md.

Test plan

  • tests/cache-adapters-config.test.ts: guarded-codegen shape, descriptor flag, and executed-registrar behaviour (skip without env / register with env / warn when the binding is genuinely missing / non-opted adapters unchanged).
  • vp test run --project unit tests/cache-adapters-config.test.ts tests/cache-adapters-build.test.ts tests/image-adapters-config.test.ts — 65 passed.
  • End-to-end repro of the issue with App Router and Pages Router apps (cache: { data: kvDataAdapter() }, prerender: { routes: '*' }): vinext build and vinext start emit no warning and serve 200.
  • Workers path: the built Cloudflare worker bundle keeps the guarded registration and still runs under workerd with the KV binding present.
  • CI-equivalent local runs: check, knip, unit, integration, package tests, the full Playwright project matrix, create-next-app (node and cloudflare init) and create-vinext-app (Cloudflare build). The only failures are pre-existing on a pristine e97de291 baseline in this macOS environment (path-derived action ids, temp-path fixtures).

…cloudflare#3132)

The generated `virtual:vinext-cache-adapters` registrar only ran a
descriptor's factory and warned on failure, so any adapter that needs
runtime bindings warned on every Node run — `vinext build` prerender,
`vinext start`, and Node dev — about a binding that cannot exist there.

Descriptors can now declare `requiresEnv`, and the registrar skips such
slots silently when the caller supplies no env. `kvDataAdapter()` sets the
flag, so Node runs keep the default in-memory handler without a warning,
while Workers callers (which always pass env) register exactly as before.
An env-present caller whose binding is genuinely missing still warns.
@pkg-pr-new

pkg-pr-new Bot commented Sep 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vinext/cloudflare

npm i https://pkg.pr.new/@vinext/cloudflare@3330

create-vinext-app

npm i https://pkg.pr.new/create-vinext-app@3330

@vinext/types

npm i https://pkg.pr.new/@vinext/types@3330

vinext

npm i https://pkg.pr.new/vinext@3330

@cloudflare/workers-response-store

npm i https://pkg.pr.new/@cloudflare/workers-response-store@3330

commit: 6921152

@github-actions

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared 6921152 against base e97de29 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 142.2 KB 142.2 KB ⚫ -0.0%
Client entry size (gzip) vinext 129.6 KB 129.6 KB ⚫ -0.0%
Dev server cold start vinext 3.17 s 3.12 s ⚫ -1.4%
Production build time vinext 3.61 s 3.61 s ⚫ -0.2%
RSC entry closure size (gzip) vinext 121.0 KB 121.0 KB ⚫ -0.0%
Server bundle size (gzip) vinext 218.3 KB 218.3 KB ⚫ -0.0%

View detailed results and traces

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

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.

Cache adapter registration always warns on Node-runtime runs (vinext build prerender / vinext start)

1 participant