Skip to content

feat(cloudflare): support durable instance selection#4110

Closed
onmax wants to merge 1 commit into
nitrojs:mainfrom
onmax:feat/cloudflare-durable-instance-selection
Closed

feat(cloudflare): support durable instance selection#4110
onmax wants to merge 1 commit into
nitrojs:mainfrom
onmax:feat/cloudflare-durable-instance-selection

Conversation

@onmax
Copy link
Copy Markdown
Contributor

@onmax onmax commented Mar 14, 2026

Summary

  • add cloudflare.durable.instanceName and cloudflare.durable.resolver
  • route Nitro durable-object stub resolution through a shared helper and virtual module
  • generate the internal durable object binding in wrangler.json for cloudflare_durable
  • add docs and regression coverage for static and resolver-based instance selection

Verification

  • pnpm build --stub
  • pnpm lint:fix
  • pnpm test:types
  • pnpm vitest run test/unit/cloudflare-durable.test.ts test/presets/cloudflare-durable.test.ts
  • pnpm vitest run test/presets/cloudflare-module.test.ts test/presets/cloudflare-pages.test.ts

@onmax onmax requested a review from pi0 as a code owner March 14, 2026 21:43
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 14, 2026

@onmax is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 14, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7b52daa6-bb2d-47c9-871c-eb4e5f1f6320

📥 Commits

Reviewing files that changed from the base of the PR and between ba5147a and 9927a0a.

📒 Files selected for processing (13)
  • docs/2.deploy/20.providers/cloudflare.md
  • src/build/virtual/_all.ts
  • src/build/virtual/cloudflare-durable.ts
  • src/presets/cloudflare/preset.ts
  • src/presets/cloudflare/runtime/_durable.ts
  • src/presets/cloudflare/runtime/cloudflare-durable.ts
  • src/presets/cloudflare/types.ts
  • src/presets/cloudflare/utils.ts
  • src/runtime/virtual/cloudflare-durable.ts
  • src/types/index.ts
  • test/fixture/server/utils/cloudflare-durable-resolver.ts
  • test/presets/cloudflare-durable.test.ts
  • test/unit/cloudflare-durable.test.ts

📝 Walkthrough

Walkthrough

This PR introduces Cloudflare Durable Objects support to Nitro. It adds type definitions, build-time virtual module generation, runtime helpers for durable stub resolution with optional custom resolvers, preset configuration, wrangler config management, and comprehensive tests for static and resolver-based durable instance naming.

Changes

Cohort / File(s) Summary
Documentation
docs/2.deploy/20.providers/cloudflare.md
Added Cloudflare Durable Objects subsection documenting the cloudflare_durable preset, configuration options (bindingName, instanceName, resolver), and example usage with defaults and resolver fallback behavior.
Type Definitions
src/presets/cloudflare/types.ts, src/presets/cloudflare/preset.ts, src/types/index.ts
Introduced CloudflareDurableResolver and CloudflareDurableResolverContext types; extended CloudflareOptions with durable configuration; exported new types in preset and main type index.
Virtual Module Infrastructure
src/build/virtual/_all.ts, src/build/virtual/cloudflare-durable.ts, src/runtime/virtual/cloudflare-durable.ts
Added build-time virtual template generator that emits bindingName, instanceName constants and conditional resolveInstanceName exports; added runtime virtual module with default exports; registered template in virtual templates array.
Runtime Helpers
src/presets/cloudflare/runtime/_durable.ts
Introduced getDurableStub, resolveDurableInstanceName, and resolveMaybe utilities for durable object binding resolution with resolver-based instance naming and fallback mechanisms.
Preset Updates
src/presets/cloudflare/runtime/cloudflare-durable.ts, src/presets/cloudflare/utils.ts
Refactored durable binding handling to use centralized getDurableStub; added wrangler config support for durable_objects bindings with configurable class names.
Tests
test/presets/cloudflare-durable.test.ts, test/unit/cloudflare-durable.test.ts, test/fixture/server/utils/cloudflare-durable-resolver.ts
Added integration tests for static and resolver-based configurations; added unit tests for instance name resolution fallback and durable stub creation; added test fixture resolver implementation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can suggest fixes for GitHub Check annotations.

Configure the reviews.tools.github-checks setting to adjust the time to wait for GitHub Checks to complete.

@onmax onmax closed this Mar 14, 2026
@onmax onmax deleted the feat/cloudflare-durable-instance-selection branch March 14, 2026 21:45
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