feat(tanstack): Pass Cloudflare Workers env context to getEnvVariable#8198
feat(tanstack): Pass Cloudflare Workers env context to getEnvVariable#8198Chat-JPTeasdale wants to merge 1 commit into
Conversation
On Cloudflare Workers, process.env and import.meta.env are not available. This adds cloudflare:workers module env resolution to the TanStack Start package, following the pattern used in @clerk/react-router where loader context is passed to getEnvVariable(). - Add cloudflareEnv.ts with initCloudflareWorkerEnv() + getCloudflareWorkerEnv() - Initialize CF env in clerkMiddleware (no-op on non-CF runtimes) - Pass CF env context through commonEnvs() → getEnvVariable(name, context) - Update getPublicEnvVariables to accept optional context Related: clerk#8197 Alternative approach to PR clerk#8196 (shared-level fix)
🦋 Changeset detectedLatest commit: 34b89fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
@ChatJPTeasdale is attempting to deploy a commit to the Clerk Production Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR adds Cloudflare Workers environment variable support to the Possibly related issues
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
|
Hello 👋 We currently close PRs after 60 days of inactivity. It's been 50 days since the last update here. If we missed this PR, please reply here. Otherwise, we'll close this PR in 10 days. Thanks for being a part of the Clerk community! 🙏 |
Description
Alternative approach to #8196 — instead of adding
cloudflare:workerssupport to the sharedgetEnvVariable, this PR fixes the issue at the TanStack Start package level by passing Cloudflare Workers env as context togetEnvVariable(), following the same pattern already used in@clerk/react-router.Related issue: #8197
Problem
On Cloudflare Workers,
@clerk/tanstack-react-startcallsgetEnvVariable('CLERK_SECRET_KEY')without a context parameter:Compare with
@clerk/react-routerwhich correctly passes context:Without context,
getEnvVariablecannot find env vars on CF Workers becauseprocess.envandimport.meta.envare not available at runtime.Solution
cloudflareEnv.ts— New module that dynamically importscloudflare:workersand caches the env object (same pattern as@clerk/astro'sinitCloudflareEnv)clerkMiddleware.ts— CallsinitCloudflareWorkerEnv()at the start of the middleware (no-op on non-CF runtimes)constants.ts—commonEnvs()now accepts optional context and passes it to allgetEnvVariable()callsutils/env.ts—getPublicEnvVariables()now accepts optional contextHow this differs from #8196
@clerk/shared@clerk/tanstack-react-startcloudflare:workersin shared@clerk/react-routerdoesBoth PRs solve the same problem. The Clerk team can choose which approach they prefer, or merge both for defense-in-depth.
Checklist
@clerk/react-routerpattern for CF context passingType of change
Summary by CodeRabbit