Repository navigation
Cache: add the OpenNextCache entrypoint (Cloudflare) - #44
Merged
Merged
Conversation
…y into core adapter feat: enhance build process with additional server bundle customization options chore: update package.json scripts for improved build and testing workflow test: add unit tests for adapter build process and server bundle generation fix: ensure proper handling of external dependencies and edge configuration in server bundle
…ests for resolve plugin
…specific overrides
…udflare specific overrides" This reverts commit 37c4d90.
…ad of throwing - Extract ValidateConfigResult type with success/message/shouldThrow/level - Convert validateFunctionOptions and validateSplittedFunctionOptions to return result objects - Remove logger dependency from validateConfig.ts - Preserve compatibilityMatrix, TODO comment, @ts-expect-error pragmas - Add 5 characterization tests in validateConfig.spec.ts - No caller impact: compileConfig.ts is the sole importer (updated in T3)
- Export OpenNextOutput interface (was internal) - Extract buildOpenNextOutput(buildOpts) for construction-only (no fs write) - Keep legacy generateOutput as thin wrapper (construction + file write) - Preserve all construction logic verbatim, including @ts-expect-error - Add 3 characterization tests in generateOutput.spec.ts - Backward compatible: byte-equivalent output to today
- Replace bare validateConfig(config) call with result-handling block - Throw on shouldThrow:true (bad routes — preserves existing behavior) - Log at appropriate level on shouldThrow:false (level field from T1) - All 3 export signatures and edge-runtime detection block unchanged - Direct callers (aws/build.ts, cloudflare/utils.ts) unaffected
…OpenNextAdapterOptions - Make OpenNextAdapterOptions<T = OpenNextOutput> and buildAdapter<T> generic - Add validateConfig override hook (runs after callback in modifyConfig) - Add generateOutput override hook (returns T, gated by skipGenerateOutput) - buildAdapter serializes override return via fs.writeFileSync (override never touches fs) - Default path uses buildOpenNextOutput (extracted in T2) - Add 5 new tests covering override behaviors + default path + skipGenerateOutput - All 16 existing adapter tests preserved; AWS/Cloudflare adapters compile with default T
When an adapter config specifies full package-specifier paths (e.g., @opennextjs/aws/overrides/wrappers/aws-lambda.js), esbuild cannot resolve them during bundling. Use createRequire(args.path).resolve() in the openNextResolvePlugin to convert package specifiers to filesystem-relative paths at build time, falling back to the original value if resolution fails. This fixes the openbuild:local build error: ERROR: Could not resolve "@opennextjs/aws/overrides/wrappers/aws-lambda.js" ERROR: Could not resolve "@opennextjs/aws/overrides/tagCache/dynamodb.js" Added test I verifying resolution of a mock package in node_modules.
…solution and improve path handling
This was referenced Aug 16, 2026
commit: |
Add a standalone cache handler function that owns the incremental cache, the tag cache and CDN invalidation, and a `cache` override that other functions use to reach it. - `adapters/cache-adapter.ts` exposes `GET/PUT/DELETE /cache/*` and `POST /cache/revalidate-tags` through `createGenericHandler`. - `build/createCacheBundle.ts` bundles it to `.open-next/cache-function`, wired into `buildAdapter` behind the new `skipCache` option and reported as `cacheFunction` in the OpenNext output. - New top level `cacheHandler` config option carries the incremental cache, tag cache and cdn invalidation overrides for that function. - New `cache` override with `fetch`, `local` and `dummy` implementations, and a shared wire format in `utils/cache-get.ts` that splits the entry metadata into headers and the payload into the body. Nothing is removed here: the existing in-process `incrementalCache` and `tagCache` overrides keep working unchanged.
Build the OpenNext cache handler function as part of the worker and expose it through a named entrypoint, so the cache can later run behind a service binding - in this worker or in one of its own. - `service-cache.ts` is a `cache` override that speaks the cache handler HTTP API over the `NEXT_CACHE_SERVICE` binding. - `buildCacheFunction` emits the bundle from `beforeServerBundle`, because the worker imports the entrypoint; core's own cache step is skipped. - `runWithCloudflareContext` initialises the Cloudflare context outside of a request, for entrypoints invoked over RPC. The origin is now populated separately, on the first call coming from the fetch handler. - `withoutSelfEntrypointServices` strips the self referencing binding before handing the config to `getPlatformProxy`, which cannot resolve a named entrypoint of the worker it is configuring. - Drop `compile-cache-assets-manifest.ts`, unreferenced. `defineCloudflareConfig` is untouched: the entrypoint is built and exported but nothing routes to it yet.
conico974
force-pushed
the
conico/cache-2-cf-entrypoint
branch
from
August 16, 2026 13:47
e65c368 to
8b63860
Compare
vicb
added this pull request to stack #52
September 21, 2026 07:15
vicb
approved these changes
Sep 21, 2026
vicb
left a comment
Contributor
There was a problem hiding this comment.
LGTM
rebased and added a couple of minor changes
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The cache handler’s dependency installation options are not propagated when building the cache function.
Review effort: Lite
Findings: None
What changed in this PR
Adds the Cloudflare OpenNextCache named entrypoint and service-binding cache client.
Changes:
- Builds and exports the cache handler entrypoint.
- Adds cache service bindings and local-development context handling.
- Updates templates, examples, tests, and changeset documentation.
| File | Summary |
|---|---|
packages/cloudflare/templates/wrangler.jsonc |
Adds the cache service binding. |
packages/cloudflare/src/utils/wrangler-config.ts |
Removes self-entrypoint services for local proxying. |
packages/cloudflare/src/utils/wrangler-config.spec.ts |
Tests Wrangler configuration rewriting. |
packages/cloudflare/src/cli/templates/worker.ts |
Exports OpenNextCache. |
packages/cloudflare/src/cli/templates/init.ts |
Supports requestless context initialization. |
packages/cloudflare/src/cli/templates/cache-entrypoint.ts |
Defines the cache entrypoint. |
packages/cloudflare/src/cli/commands/utils/helpers.ts |
Uses sanitized Wrangler configuration. |
packages/cloudflare/src/cli/build/open-next/compile-cache-entrypoint.ts |
Compiles the entrypoint bundle. |
packages/cloudflare/src/cli/build/open-next/compile-cache-assets-manifest.ts |
Removes obsolete manifest generation. |
packages/cloudflare/src/cli/adapter.ts |
Builds the cache function; cache handler install options need propagation. |
packages/cloudflare/src/api/overrides/cache/service-cache.ts |
Implements the service-binding cache client. |
packages/cloudflare/src/api/overrides/cache/service-cache.spec.ts |
Tests cache service operations. |
packages/cloudflare/src/api/cloudflare-context.ts |
Handles self-entrypoint services in development. |
examples-cloudflare/prisma/wrangler.jsonc |
Adds the cache binding. |
examples-cloudflare/playground16/wrangler.jsonc |
Adds the cache binding. |
examples-cloudflare/overrides/static-assets-incremental-cache/wrangler.jsonc |
Adds the cache binding. |
examples-cloudflare/overrides/r2-incremental-cache/wrangler.jsonc |
Adds cache bindings. |
examples-cloudflare/overrides/memory-queue/wrangler.jsonc |
Adds the cache binding. |
examples-cloudflare/overrides/kv-tag-next/wrangler.e2e.jsonc |
Adds the cache binding. |
examples-cloudflare/overrides/d1-tag-next/wrangler.e2e.jsonc |
Adds the cache binding. |
examples-cloudflare/e2e/pages-router/wrangler.jsonc |
Adds the cache binding. |
examples-cloudflare/e2e/experimental/wrangler.jsonc |
Adds the cache binding. |
examples-cloudflare/e2e/app-router/wrangler.jsonc |
Adds the cache binding. |
examples-cloudflare/e2e/app-pages-router/wrangler.jsonc |
Adds the cache binding. |
.changeset/cloudflare-cache-entrypoint.md |
Documents the new entrypoint and configuration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Author
|
Thanks for the review and the changes @vicb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds the cache handler function as part of the worker and exposes it through the
OpenNextCachenamed entrypoint.service-cache.tsis acacheoverride speaking the cache handler HTTP API over theNEXT_CACHE_SERVICEbinding.buildCacheFunctionemits the bundle frombeforeServerBundle, because the worker imports the entrypoint; core's own cache step is skipped.runWithCloudflareContextinitialises the Cloudflare context outside of a request, for entrypoints invoked over RPC. The origin is populated separately, on the first call coming from the fetch handler.withoutSelfEntrypointServicesstrips the self referencing binding before handing the config togetPlatformProxy, which cannot resolve a named entrypoint of the worker it is configuring.compile-cache-assets-manifest.ts, unreferenced.Additive.
defineCloudflareConfigis untouched — the entrypoint is built and exported but nothing routes to it yet. It is landed first so that PR 3 can flip core and Cloudflare together without leaving Cloudflare without a working cache.