Skip to content

fix(astro): Restore Cloudflare Pages compatibility broken by cloudflare:workers env#8136

Merged
jescalan merged 1 commit intoclerk:mainfrom
mlafeldt:fix/astro-cloudflare-env-fallback
Mar 20, 2026
Merged

fix(astro): Restore Cloudflare Pages compatibility broken by cloudflare:workers env#8136
jescalan merged 1 commit intoclerk:mainfrom
mlafeldt:fix/astro-cloudflare-env-fallback

Conversation

@mlafeldt
Copy link
Contributor

@mlafeldt mlafeldt commented Mar 20, 2026

On Cloudflare Pages (Astro v5), cloudflare:workers env may be available but lack dashboard secrets (CLERK_SECRET_KEY, etc.) that are only present in the fetch handler's env param (locals.runtime.env).

The current code short-circuits on cloudflareEnv without checking whether the requested key actually exists, preventing the fallback chain from ever reaching locals.runtime.env. This causes all SSR pages to break with [object Object] responses.

Fix: check if the value is defined before returning from the cloudflareEnv branch, allowing the fallback to locals.runtime.env.

Follow-up fix to #7890

Description

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Bug Fixes
    • Fixed environment-variable fallback on Cloudflare Pages so required secrets are sourced from runtime fallbacks when the platform omits them.
  • Tests
    • Added a test validating the fallback chain for env values on Cloudflare Pages.
  • Chores
    • Added a changeset recording a patch release for the fix.

@changeset-bot
Copy link

changeset-bot bot commented Mar 20, 2026

🦋 Changeset detected

Latest commit: eec0c0f

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

This PR includes changesets to release 1 package
Name Type
@clerk/astro Patch

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

@vercel
Copy link

vercel bot commented Mar 20, 2026

@mlafeldt is attempting to deploy a commit to the Clerk Production Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added the astro label Mar 20, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9cace598-1f37-499d-9751-d5fe9adcf44d

📥 Commits

Reviewing files that changed from the base of the PR and between f093e77 and eec0c0f.

📒 Files selected for processing (3)
  • .changeset/fix-astro-cf-pages-env-fallback.md
  • packages/astro/src/server/__tests__/get-safe-env.test.ts
  • packages/astro/src/server/get-safe-env.ts

📝 Walkthrough

Walkthrough

This pull request adds a Cloudflare Pages environment variable resolution fix to the @clerk/astro package. Changes include a new changeset marking a patch release, an updated getContextEnvVar implementation in get-safe-env.ts that treats missing keys from the cloudflare:workers env as absent and continues to fallback sources, and a new test verifying the fallback chain retrieves variables from locals.runtime.env when they are not present in the Workers environment.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: restoring Cloudflare Pages compatibility by addressing the cloudflare:workers env issue, which directly matches the core problem solved in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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.

❤️ Share

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

Copy link
Member

@wobsoriano wobsoriano left a comment

Choose a reason for hiding this comment

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

Thanks Mathias!

…re:workers env

On Cloudflare Pages (Astro v5), `cloudflare:workers` env may be
available but lack dashboard secrets (CLERK_SECRET_KEY, etc.) that are
only present in the fetch handler's env param (locals.runtime.env).

The current code short-circuits on cloudflareEnv without checking
whether the requested key actually exists, preventing the fallback
chain from ever reaching locals.runtime.env. This causes all SSR pages
to break with `[object Object]` responses.

Fix: check if the value is defined before returning from the
cloudflareEnv branch, allowing the fallback to locals.runtime.env.
@jescalan jescalan force-pushed the fix/astro-cloudflare-env-fallback branch from f093e77 to eec0c0f Compare March 20, 2026 20:36
@vercel
Copy link

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Mar 20, 2026 8:57pm

Request Review

@jescalan jescalan enabled auto-merge (squash) March 20, 2026 21:28
@jescalan jescalan disabled auto-merge March 20, 2026 21:28
@jescalan jescalan merged commit 9b71736 into clerk:main Mar 20, 2026
19 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants