Skip to content

Fix Cloudflare adapter circular import with custom fetchFile#16968

Merged
matthewp merged 1 commit into
mainfrom
flue/fix-16956
Jun 5, 2026
Merged

Fix Cloudflare adapter circular import with custom fetchFile#16968
matthewp merged 1 commit into
mainfrom
flue/fix-16956

Conversation

@astrobot-houston

Copy link
Copy Markdown
Contributor

Changes

  • Defers createApp() and setGetEnv() initialization in @astrojs/cloudflare/fetch to the first cf() call
  • Prevents circular import crashes when custom fetchFile statically imports cf from @astrojs/cloudflare/fetch
  • Uses lazy initialization pattern via ensureInitialized() helper to break the module evaluation cycle

Testing

  • Added fetch-lazy-init.test.ts covering custom fetchFile scenarios with static imports
  • Verified existing cf-helpers tests continue passing
  • Confirmed no regression with advancedRouting: true (boolean) usage

Docs

  • No docs update needed, this fixes the documented usage pattern that was previously broken

Closes #16956

@changeset-bot

changeset-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a44f707

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

This PR includes changesets to release 37 packages
Name Type
@astrojs/cloudflare Patch
@test/astro-cloudflare-node-prerender-mdx Patch
@test/astro-cloudflare Patch
@test/astro-cloudflare-allowed-hosts Patch
@test/astro-cloudflare-astro-dev-platform Patch
@test/astro-cloudflare-astro-env Patch
@test/astro-cloudflare-binding-image-service Patch
@test/astro-cloudflare-cache-provider-wait-until Patch
@test/astro-cloudflare-client-address Patch
@test/astro-cloudflare-compile-image-service Patch
@test/astro-cloudflare-custom-entryfile Patch
@test/astro-cloudflare-dev-image-endpoint Patch
@test/astro-cloudflare-external-image-service Patch
@test/astro-cloudflare-external-redirects Patch
@test/astro-cloudflare-internal-redirects Patch
@test/astro-cloudflare-no-output Patch
@test/astro-cloudflare-prerender-node-env Patch
@test/astro-cloudflare-prerender-queue-consumers Patch
@test/astro-cloudflare-prerender-styles Patch
@test/astro-cloudflare-prerenderer-errors Patch
@test/routing-priority-cloudflare Patch
@test/cf-server-entry Patch
@test/astro-cloudflare-server-island-prerender-framework Patch
@test/astro-cloudflare-sessions Patch
@test/astro-cloudflare-sql-import Patch
@test/cf-ssr-deps Patch
@test/astro-cloudflare-static Patch
@test/astro-cloudflare-svelte-rune-deps Patch
@test/astro-cloudflare-top-level-return Patch
@test/cf-user-optimize-deps Patch
@test/astro-cloudflare-vite-plugin Patch
@test/astro-cloudflare-with-base Patch
@test/astro-cloudflare-with-react Patch
@test/astro-cloudflare-with-solid-js Patch
@test/astro-cloudflare-with-svelte Patch
@test/astro-cloudflare-with-vue Patch
@test/astro-cloudflare-wrangler-preview-platform 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

@github-actions github-actions Bot added the pkg: integration Related to any renderer integration (scope) label Jun 4, 2026
@matthewp matthewp merged commit 7a5c001 into main Jun 5, 2026
26 checks passed
@matthewp matthewp deleted the flue/fix-16956 branch June 5, 2026 12:29
@astrobot-houston astrobot-houston mentioned this pull request Jun 5, 2026
matthewp pushed a commit that referenced this pull request Jun 8, 2026
* fix(errors): correct param key in getStaticPaths error-doc examples (slug → id) (#16976)

* fix(cloudflare): defer createApp/setGetEnv in fetch.ts to avoid circular import crash (#16956) (#16968)

* fix(fetch): sync request.url with forwarded headers in FetchState (#16947)

* fix(fetch): sync request.url with forwarded headers in FetchState (#16945)

* chore: improve tests and solution

---------

Co-authored-by: astrobot-houston <fred+astrobot@astro.build>

* chore: avoid an unwanted mdx major bump (#16977)

* chore(renovate): bump max memory (#16993)

---------

Co-authored-by: Minh Lê <115204145+DucMinhNe@users.noreply.github.com>
Co-authored-by: Houston (Bot) <108291165+astrobot-houston@users.noreply.github.com>
Co-authored-by: Emanuele Stoppa <estoppa@cloudflare.com>
Co-authored-by: astrobot-houston <fred+astrobot@astro.build>
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
florian-lefebvre added a commit that referenced this pull request Jun 8, 2026
Co-authored-by: astrobot-houston <fred+astrobot@astro.build>
Co-authored-by: Minh Lê <115204145+DucMinhNe@users.noreply.github.com>
Co-authored-by: Houston (Bot) <108291165+astrobot-houston@users.noreply.github.com>
Co-authored-by: Emanuele Stoppa <estoppa@cloudflare.com>
Co-authored-by: ocavue <ocavue@users.noreply.github.com>
fix(errors): correct param key in getStaticPaths error-doc examples (slug → id) (#16976)
fix(cloudflare): defer createApp/setGetEnv in fetch.ts to avoid circular import crash (#16956) (#16968)
fix(fetch): sync request.url with forwarded headers in FetchState (#16947)
fix(fetch): sync request.url with forwarded headers in FetchState (#16945)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix verified Reporter confirmed the triage bot fix works pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@astrojs/cloudflare: advancedRouting fetchFile crashes build with "createGetEnv is not a function"

2 participants