[Feature] Add Cloudflare Workers adapter for shopify-app-react-router#3160
Open
kayluhb wants to merge 3 commits intoShopify:mainfrom
Open
[Feature] Add Cloudflare Workers adapter for shopify-app-react-router#3160kayluhb wants to merge 3 commits intoShopify:mainfrom
kayluhb wants to merge 3 commits intoShopify:mainfrom
Conversation
Mirrors the structure of the existing /adapters/node, pulling in the underlying @shopify/shopify-api/adapters/cf-worker runtime so consumers can deploy to Cloudflare Workers without needing the nodejs_compat flag just to satisfy the Shopify SDK. The adapter identifies itself as `React Router (Cloudflare Worker)` and honours `process.env.APP_BRIDGE_URL` when the runtime exposes it (nodejs_compat enabled) — otherwise the env-driven override is silently skipped and users can still call `setAppBridgeUrlOverride` directly. Tests cover both the runtime string and the App Bridge URL override.
- Add `shopify-app-react-router-server-cloudflare` Jest project that wires `src/server/adapters/cloudflare/__tests__/setup-jest.ts`, mirroring the existing `-server-node` project and the sibling shopify-app-remix package's vercel wiring. Without this, the setup file was dead code and the full server test suite was never exercised under the Cloudflare Worker runtime. Test count goes from 350 across 3 projects to 679 across 4 projects; all pass. - Narrow the `process.env` try/catch in the cloudflare adapter to only swallow `ReferenceError` (the "process is not defined" case on Workers without `nodejs_compat`). Any other error — e.g. future validation in `setAppBridgeUrlOverride` — is re-thrown instead of silently ignored. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The prior wording implied full independence from `nodejs_compat`. The adapter does load without it, but the `process.env.APP_BRIDGE_URL` override path still requires `process` to be defined. Spell out the caveat and point to `setAppBridgeUrlOverride` as the explicit alternative so reviewers/users don't hit a surprise. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
WHY are these changes introduced?
Fixes #3161 (just filed — sorry for the out-of-order; PR was already up when I re-read CONTRIBUTING.md).
@shopify/shopify-app-react-routercurrently only ships an/adapters/nodeentry point. Anyone deploying a React Router 7 Shopify app to Cloudflare Workers today has to:nodejs_compatcompatibility flag inwrangler.tomlpurely so the Node adapter's polyfills load, even though every Shopify SDK code path actually runs on Web standards (fetch,Request/Response,crypto.subtle) that Workers natively supports.React Router (Node)in telemetry/logs, which is misleading.The underlying
@shopify/shopify-apipackage already has/adapters/cf-worker(used byshopify-app-expressconsumers and tested via miniflare). The wrapper layer is the missing piece — this PR adds it.WHAT is this pull request doing?
Adds
@shopify/shopify-app-react-router/adapters/cloudflare:src/server/adapters/cloudflare/index.ts— imports the existing@shopify/shopify-api/adapters/cf-workerruntime, then sets the runtime string toReact Router (Cloudflare Worker). Honoursprocess.env.APP_BRIDGE_URLwhennodejs_compatis enabled, and falls back gracefully (try/catch) whenprocessis undefined (Workers without nodejs_compat) — in that case users can still callsetAppBridgeUrlOverridedirectly.src/server/adapters/cloudflare/__tests__/setup-jest.ts— mirrors the node adapter's setup file.src/server/adapters/__tests__/cloudflare-app-bridge-url.test.ts— mirrors the existingnode-app-bridge-url.test.ts.src/server/adapters/__tests__/cloudflare-runtime-string.test.ts— verifies the runtime string is set correctly.@shopify/shopify-app-react-router).No changes to existing files. Rollup auto-discovers adapter directories, so the build picks up the new entry point with no config changes. Package
exportsmap already covers./adapters/*, so consumers can import via@shopify/shopify-app-react-router/adapters/cloudflareimmediately.Verified locally:
pnpm build(rollup + tsc) — emitsdist/{esm,cjs,ts}/server/adapters/cloudflare/index.{mjs,js,d.ts}alongside the node adapter.pnpm test— 350 tests pass across 51 suites (2 new tests added).pnpm lint— clean.Type of change
Checklist
pnpm changesetto create a draft changelog entry (do NOT update theCHANGELOG.mdfiles manually)/adapters/nodeis undocumented). Happy to add an "Adapters" section to the README in this PR if you'd like, or split it into a follow-up — your call.