@astrojs/cloudflare
🐞 Patch Changes
-
#17363
3f4efc5Thanks @astrobot-houston! - Fixesastro preview --opennot opening a browser when using an adapter with a custom preview entrypoint, such as@astrojs/cloudflare -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
🐞 Patch Changes
-
#17323
4298883Thanks @ematipico! - Fixes build-time image optimization ignoring a custom image service registered by an integrationPreviously, when using
imageService: 'compile'orimageService: 'custom', a custom image service was only respected if it was set directly in theimage.serviceoption ofastro.config. If an integration registered the service instead, images were silently optimized with the default Sharp service at build time. A custom image service now transforms your images at build time no matter how it was configured. -
#17323
4298883Thanks @ematipico! - Prebundlesastro/componentsand the<ClientRouter />transition runtime modules in the dev server environment so pages using them no longer trigger a mid-session dep optimizer reload, which caused React “Invalid hook call” errors in islands on the first request after a cold cache -
#17323
4298883Thanks @ematipico! - Fixes an issue wherevarsweren’t available at build time. Now the adapter loadsvarsfrom the Wrangler config soastro:envpublic variables resolve at build time -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
🐞 Patch Changes
- Updated dependencies [
eb6f97e]:- @astrojs/internal-helpers@0.10.1
- @astrojs/underscore-redirects@1.0.3
- Updated dependencies [
🍿 Minor Changes
-
#17099
fdab7ceThanks @adamchal! - Adds configured image service support with thecompileandcustomoptions.The Cloudflare adapter supports various options that affect how images are processed for both pre-rendered and on-demand routes:
- Setting
imageService: 'compile'now ensures it is used for pre-rendered routes. When no custom image service is defined, the behavior remains unchanged. - With
imageService: 'custom', assets are now processed at build time for pre-rendered routes. If you have configured an image service, it will be bundled to handle images at runtime; otherwise, the behavior remains unchanged. - The other
imageServiceoptions remain unchanged.
Learn more about the image service options available in the Cloudflare adapter guide.
- Setting
🐞 Patch Changes
-
#17236
c411200Thanks @matthewp! - Prevents warnings in the Cloudflare adapter about optimizing the@astrojs/cloudflare/entrypoints/servermodule in dev. -
#17249
02b73b0Thanks @ematipico! - Fixes an issue where thepeerDependenciesfield used incorrect dependencies. -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
🐞 Patch Changes
-
#17049
ffceaa2Thanks @astrobot-houston! - Fixes prerender errors being silently swallowed when pages throw during rendering in workerd, causingastro buildto exit 0 and emit truncated HTML. The response body is now fully buffered inside workerd before being sent back to the build process, so streaming errors are caught and surfaced as build failures with clear error messages. -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
🐞 Patch Changes
-
#17175
7a7d879Thanks @astrobot-houston! - Fixesastro devOOM crashes for@astrojs/cloudflareusers on Vite 8 by migrating the frontmatter scan plugin to Rolldown-compatible options. -
#17187
0db4b57Thanks @matthewp! - Fixes React invalid hook warning during cold SSR optimizer reload when using ClientRouter -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
✨ Major Changes
🍿 Minor Changes
-
#16335
9a53f77Thanks @ascorbic! - Adds an opt-in CDN cache provider for Astro route caching on Cloudflare Workers[!WARNING] This provider requires the Cloudflare Workers Cache feature, which is currently in private beta. It is opt-in: nothing changes unless you import
cacheCloudflare()and set it as your provider. But without beta access it does not work and should not be used. Cloudflare Workers run in front of the cache, so cached responses are never served, and callingcache.invalidate()throws an error.Setup
Import
cacheCloudflare()from@astrojs/cloudflare/cacheand set it as your cache provider:import { defineConfig } from 'astro/config';import cloudflare from '@astrojs/cloudflare';import { cacheCloudflare } from '@astrojs/cloudflare/cache';export default defineConfig({adapter: cloudflare(),cache: {provider: cacheCloudflare(),},});The adapter automatically enables the Worker caching layer when a Cloudflare cache provider is configured. No manual wrangler.jsonc changes are needed.
Caching responses
Use
Astro.cache.set()in your pages and API routes to cache responses. The provider setsCloudflare-CDN-Cache-ControlandCache-Tagheaders, which are read by Cloudflare’s built-in caching layer. Cache hits bypass Worker execution entirely, meaning your Worker is not invoked for cached responses.---Astro.cache.set({ maxAge: 300, tags: ['products'] });const data = await fetchProducts();---<ProductList items={data} />You can also set cache rules for groups of routes in your config:
cache: { provider: cacheCloudflare() },routeRules: {'/products/[...slug]': { maxAge: 3600, tags: ['products'] },'/api/[...path]': { maxAge: 60, swr: 600 },},Invalidation
Purge cached responses by tag or path from any API route or server endpoint:
src/pages/api/purge.ts export async function POST({ request, cache }) {await cache.invalidate({ tags: ['products'] });return new Response('Purged');}// Path-based invalidation (implemented via an auto-generated path tag)await cache.invalidate({ path: '/products/123' });Both tag-based and path-based invalidation are supported.
🐞 Patch Changes
-
#16961
96398e8Thanks @adamchal! - Speeds upastro syncby no longer starting the Cloudflare runtime during type generation -
#16671
fd926fdThanks @alexanderniebuhr! - Removes deprecations warnings added in Astro v6 for Cloudflare specific Astro.locals properties. -
#17027
241250bThanks @ocavue! - Triggers beta prereleases for packages that are still on alpha -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
🍿 Minor Changes
-
#16571
d4b0cd1Thanks @MA2153! - Sets immutable cache headers for static assetsStatic assets under
_astrocan be cached to improve performance. The adapter now automatically injects aCache-Controlheader at build time when possible.
🐞 Patch Changes
-
#16968
7a5c001Thanks @astrobot-houston! - Fixes a build crash when usingexperimental.advancedRoutingwith a customfetchFilethat statically importscffrom@astrojs/cloudflare/fetch. The circular dependency between@astrojs/cloudflare/fetchandastro/app/entrypointcausedcreateApporcreateGetEnvto beundefinedat module evaluation time. Initialization is now deferred to the firstcf()call, breaking the cycle. -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
🐞 Patch Changes
-
#16990
ebeb830Thanks @ocavue! - Fixes a build crash when usingexperimental.advancedRoutingwith a customfetchFilethat statically importscffrom@astrojs/cloudflare/fetch. The circular dependency between@astrojs/cloudflare/fetchandastro/app/entrypointcausedcreateApporcreateGetEnvto beundefinedat module evaluation time. Initialization is now deferred to the firstcf()call, breaking the cycle. -
#16671
fd926fdThanks @alexanderniebuhr! - Removes deprecations warnings added in Astro v6 for Cloudflare specific Astro.locals properties. -
Updated dependencies [
1f07343,1e000e2,c63e7e4,ebeb830,10229f7]:- astro@7.0.0-alpha.2
- @astrojs/underscore-redirects@1.0.3
-
🐞 Patch Changes
-
#16914
4bdd240Thanks @matthewp! - Fixesastro/fetchandastro/honobeing discovered at runtime during dev instead of pre-bundled -
#16693
9e6edc2Thanks @ArmandPhilippot! - Fixes a link in the documentation specifying where to open an issue for the adapter. -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
🍿 Minor Changes
-
#16729
01aa164Thanks @matthewp! - Adds@astrojs/cloudflare/fetchand@astrojs/cloudflare/honoexports for composing Cloudflare-specific setup with Astro’s advanced routing handlers.@astrojs/cloudflare/fetchFor use with
astro/fetchin a custom fetch handler:import { astro, FetchState } from 'astro/fetch';import { cf } from '@astrojs/cloudflare/fetch';export default {async fetch(request: Request, env: Env, ctx: ExecutionContext) {const state = new FetchState(request);const asset = await cf(state, env, ctx);if (asset) return asset;return astro(state);},};@astrojs/cloudflare/honoFor use with
astro/honoas Hono middleware:import { Hono } from 'hono';import { actions, middleware, pages, i18n } from 'astro/hono';import { cf } from '@astrojs/cloudflare/hono';const app = new Hono<{ Bindings: Env }>();app.use(cf());app.use(actions());app.use(middleware());app.use(pages());app.use(i18n());export default app;Both handlers configure SESSION KV bindings, static asset serving via the ASSETS binding,
locals.cfContext, client address,waitUntil, and prerendered error page fetch.
🐞 Patch Changes
-
#16868
f9bae95Thanks @helio-cf! - Fixes user options passed tocloudflare({...})(remoteBindings,inspectorPort,persistState,configPath,auxiliaryWorkers) being silently ignored duringastro preview. The adapter now resolves the full@cloudflare/vite-pluginconfig once at integration setup time and reuses that single resolved value across the dev/build plugin, the prerenderer’s preview server, and theastro previewentrypoint, so user options can no longer be dropped at one of the call sites. -
#16468
4cff3a1Thanks @matthewp! - Fixes static Cloudflare builds with server islands or image endpoints that failed at preview time due to mismatched output directories. -
Updated dependencies [
f732f3c]:- @astrojs/internal-helpers@0.10.0
- @astrojs/underscore-redirects@1.0.3
-
🐞 Patch Changes
-
#16607
98297afThanks @alexanderflodin! - Fixes incorrectassets.directoryin the generatedwrangler.jsonwhen abasepath is configured -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
🐞 Patch Changes
-
#16769
428cb1bThanks @astrobot-houston! - Forwards user-providedoptimizeDepssettings (exclude, include, esbuildOptions.loader) to SSR/prerender environments. Previously, top-levelvite.optimizeDepsin the Astro config was silently ignored for server environments because Vite 6 scopes it to client-only and the adapter’sconfigEnvironmenthook did not forward it. This caused packages with non-standard file types (e.g..datafiles) to fail during dev-mode dependency optimization with errors like “No loader is configured for ‘.data’ files”. -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
🐞 Patch Changes
-
#16801
d619277Thanks @ematipico! - Reverts a change to the esbuild dep-scan plugin that causedastro checkandastro buildto fail by making esbuild incorrectly bundlevirtual:modules (e.g. from expressive-code) -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
🐞 Patch Changes
-
#16708
bb709ffThanks @fkatsuhiro! - Fixed a bug where a cascade of reloads would cause the page to crash during the first visit when building or developing with Cloudflare SSR in Astro v6 due to dependency loading issues. -
Updated dependencies []:
- @astrojs/underscore-redirects@1.0.3
-
🐞 Patch Changes
-
#16707
2ff3f8fThanks @helio-cf! - FixesremoteBindings: falsebeing ignored duringastro build. The Cloudflare prerenderer’s internal Vite preview server now receives the user’s adapter options, so remote-flagged bindings (e.g. a D1 database withremote: trueinwrangler.toml) are emulated locally during build, matching the existingastro devbehavior. -
#16652
98c32ccThanks @greatjourney589! - Fixes user-declared KV namespace bindings being duplicated in the generateddist/server/wrangler.json, which caused wrangler validation to fail with “assigned to multiple KV Namespace bindings.” The Astro Cloudflare config customizer now returns only the auto-injected SESSIONbinding and lets@cloudflare/vite-pluginmerge it with the user’s wrangler config, instead of pre-merging the user’s bindings into the output. -
#16272
4f9521eThanks @barry3406! - Fixes.astrofiles failing withNo matching export in "html:..." for import "default"when default-imported from a.tsfile -
#15723
9256345Thanks @rururux! - Fixes an issue where the<Prism />component failed to work in Cloudflare Workers. -
Updated dependencies [
d365c97]:- @astrojs/internal-helpers@0.9.1
- @astrojs/underscore-redirects@1.0.3
-
🍿 Minor Changes
- #16639
4d72482Thanks @ematipico! - The adapter now depends on Astro 6.3.0.
- #16639