fix(astro): read Cloudflare env via cloudflare:workers, not removed locals.runtime.env#1558
Open
pauldiv wants to merge 1 commit into
Open
fix(astro): read Cloudflare env via cloudflare:workers, not removed locals.runtime.env#1558pauldiv wants to merge 1 commit into
pauldiv wants to merge 1 commit into
Conversation
…ocals.runtime.env Astro v6 removed Astro.locals.runtime.env. GitHub-mode API routes (/api/keystatic/github/*) crashed with a 500 under @astrojs/cloudflare on Astro 6+, confirmed both in astro dev and a real deployed Worker. Reads the Cloudflare runtime env via a dynamic cloudflare:workers import instead, matching what the removed API's own error message recommends. Falls back to the previous context.locals.runtime.env shape (wrapped in its own try/catch, since that access itself throws on Astro v6+) for other adapters or older Astro versions, so this stays adapter-agnostic rather than Cloudflare-only. Fixes Thinkmill#1554
🦋 Changeset detectedLatest commit: 2d794b8 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 |
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.
Summary
Fixes #1554. GitHub-mode API routes (
/api/keystatic/github/*) crash with a 500 under@astrojs/cloudflareon Astro 6+ —Astro.locals.runtime.envwas removed, andkeystatic-astro-api.jsstill reads it.Confirmed the crash both in
astro devand a real deployed Cloudflare Worker (viawrangler tail), and confirmed this fix resolves it in both, on our own project (Astro 7.0.9,@astrojs/cloudflare14.1.3,wrangler4.110.0).What changed
packages/astro/src/api.tsxnow reads the Cloudflare runtime env via a dynamiccloudflare:workersimport — exactly what the removed API's own error message recommends — instead ofcontext.locals.runtime.env. Falls back to the old shape (in its own try/catch, since that access itself throws on Astro v6+) for other adapters or older Astro versions, so the fix stays adapter-agnostic rather than hardcoding a Cloudflare-only assumption into a shared file.Also flagged in the issue but not attempted here: the GitHub App creation wizard (
/keystaticguided setup) has a separate, unrelated bug under this same adapter combo (module is not defined, React/workerd bundling) — didn't touch that in this PR, wanted to keep this one focused on the API crash.Test plan
wrangler tailpatch-packagefirst, confirmed it resolves the crash (replaced with a clean "missing credentials" error, then a working OAuth redirect once credentials were set) both inastro devand the real deploymenttscfor syntax/type correctnessAdded a changeset (patch bump for
@keystatic/astro).