Skip to content

[wrangler] Extract remote bindings into shared packages#12946

Draft
penalosa wants to merge 1 commit intopenalosa/shared-binding-helpersfrom
penalosa/extract-remote-bindings
Draft

[wrangler] Extract remote bindings into shared packages#12946
penalosa wants to merge 1 commit intopenalosa/shared-binding-helpersfrom
penalosa/extract-remote-bindings

Conversation

@penalosa
Copy link
Contributor

@penalosa penalosa commented Mar 18, 2026

Extract remote bindings session setup into @cloudflare/remote-bindings.

Stacked on #12948.

  • add @cloudflare/remote-bindings — preview session creation, token exchange, and minimal Node.js HTTP proxy (replaces the full DevEnv pipeline)
  • rewrite wrangler's remoteBindings/index.ts to delegate to the new package with a backward-compatible wrapper
  • inline the ProxyServerWorker template at build time via a rolldown virtual module plugin (no readFileSync at runtime)

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal shared implementation, no user-facing changes

@penalosa penalosa requested a review from a team as a code owner March 18, 2026 00:53
@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2026

🦋 Changeset detected

Latest commit: 58119b6

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod
Copy link
Contributor

workers-devprod commented Mar 18, 2026

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/remote-bindings/eslint.config.mjs: [@cloudflare/wrangler]
  • packages/remote-bindings/package.json: [@cloudflare/wrangler]
  • packages/remote-bindings/src/api/fetch.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/src/api/preview-session.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/src/api/preview-token.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/src/api/subdomain.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/src/api/upload-form.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/src/index.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/src/pick-remote-bindings.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/src/proxy-server.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/src/start-session.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/src/types.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/src/virtual.d.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/templates/ProxyServerWorker.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/test/stubs/proxy-server-worker.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/test/pick-remote-bindings.test.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/test/start-session.test.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/tsconfig.json: [@cloudflare/wrangler]
  • packages/remote-bindings/tsdown.config.ts: [@cloudflare/wrangler]
  • packages/remote-bindings/vitest.config.ts: [@cloudflare/wrangler]
  • packages/workers-utils/package.json: [@cloudflare/wrangler]
  • packages/workers-utils/src/access.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/index.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/to-worker-metadata-bindings.ts: [@cloudflare/wrangler]
  • packages/wrangler/e2e/remote-binding/miniflare-remote-resources.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/e2e/remote-binding/remote-bindings-api.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/package.json: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/dev/remote-bindings-errors.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/dev/remote-bindings.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/api/remoteBindings/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/api/remoteBindings/start-remote-proxy-session.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/access.ts: [@cloudflare/wrangler]
  • pnpm-lock.yaml: [@cloudflare/wrangler]

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

⚠️ Issues found

.changeset/green-pens-jump.md

Version type (patch): Acceptable. The existing startRemoteProxySession() programmatic API behavior is preserved via a compatibility wrapper, so patch is appropriate for wrangler.

Changelog quality: Good. The title is clear and the body explains what changed, what replaced what, and that backward compatibility is maintained.

Markdown headers: None present. Pass.

Package coverage: The changeset only covers wrangler. However, this PR introduces a new @cloudflare/remote-bindings workspace package (visible in pnpm-lock.yaml), and wrangler lists it as a runtime dependency. If @cloudflare/remote-bindings is a publicly published package, it needs its own changeset entry — new packages being published for the first time are user-facing changes. Please confirm whether @cloudflare/remote-bindings is private (i.e., "private": true in its package.json). If it is public, a separate changeset covering "@cloudflare/remote-bindings": minor (new package introduction) should be added.

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 18, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12946

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12946

miniflare

npm i https://pkg.pr.new/miniflare@12946

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12946

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12946

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12946

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12946

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12946

wrangler

npm i https://pkg.pr.new/wrangler@12946

commit: 8705073

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 8 additional findings in Devin Review.

Open in Devin Review

undefined,
complianceRegion
);
return result.subdomain;
Copy link
Contributor

Choose a reason for hiding this comment

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

🔴 Missing .workers.dev suffix in remote-bindings subdomain, causing all proxy requests to target wrong host

The new getWorkersDevSubdomain in packages/remote-bindings/src/api/subdomain.ts returns only the raw subdomain from the API (e.g., my-account), but the old wrangler implementation at packages/wrangler/src/routes.ts:32 appends .workers.dev (and a compliance-region subdomain when applicable). This means createPreviewSession at packages/remote-bindings/src/api/preview-session.ts:84 constructs a host like worker-name.my-account instead of the correct worker-name.my-account.workers.dev. The ProxyServer then proxies all HTTP/WebSocket traffic to this incomplete hostname, causing every remote binding request to fail.

Old wrangler code that appends the suffix
// packages/wrangler/src/routes.ts:32
return `${subdomain}${getComplianceRegionSubdomain(complianceConfig)}.workers.dev`;

New code that omits it:

// packages/remote-bindings/src/api/subdomain.ts:17
return result.subdomain;
Prompt for agents
In packages/remote-bindings/src/api/subdomain.ts, the function getWorkersDevSubdomain must append .workers.dev to the raw subdomain returned by the API. Additionally, it should handle the compliance region subdomain (e.g. for EU regions). The old wrangler code at packages/wrangler/src/routes.ts:32 did: return `${subdomain}${getComplianceRegionSubdomain(complianceConfig)}.workers.dev`. The fix should change line 17 from `return result.subdomain;` to something like `return `${result.subdomain}${complianceRegion === 'eu' ? '.eu' : ''}.workers.dev`;` — verify with the existing getComplianceRegionSubdomain helper to get the exact logic right.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@penalosa penalosa force-pushed the penalosa/extract-remote-bindings branch from 38eeda5 to 8705073 Compare March 18, 2026 02:36
@penalosa penalosa changed the base branch from main to penalosa/shared-binding-helpers March 18, 2026 02:37
@penalosa penalosa marked this pull request as draft March 18, 2026 02:49
@penalosa penalosa force-pushed the penalosa/shared-binding-helpers branch 3 times, most recently from 048c516 to 019587c Compare March 18, 2026 03:20
Replace the full DevEnv pipeline for remote preview sessions with direct API calls and a minimal Node.js HTTP proxy. Wrangler's programmatic API is preserved via a compatibility wrapper that resolves auth and delegates to the new package.
@penalosa penalosa force-pushed the penalosa/extract-remote-bindings branch from 8705073 to 58119b6 Compare March 18, 2026 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants