From 5ae54c6da11ac3e6f507597aba9796b6da86a0dd Mon Sep 17 00:00:00 2001 From: Adam Chalemian Date: Wed, 3 Jun 2026 13:50:43 -0400 Subject: [PATCH 1/2] fix(cloudflare): skip runtime startup during type generation --- .changeset/cloudflare-skip-sync-runtime.md | 5 ++++ packages/integrations/cloudflare/src/index.ts | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 .changeset/cloudflare-skip-sync-runtime.md diff --git a/.changeset/cloudflare-skip-sync-runtime.md b/.changeset/cloudflare-skip-sync-runtime.md new file mode 100644 index 000000000000..138567d3bc51 --- /dev/null +++ b/.changeset/cloudflare-skip-sync-runtime.md @@ -0,0 +1,5 @@ +--- +"@astrojs/cloudflare": patch +--- + +Speeds up `astro sync` by no longer starting the Cloudflare runtime during type generation diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 44c3f57f3d02..6d8187b06089 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -174,6 +174,7 @@ export default function createIntegration({ const needsImagesBindingForDev = isCompile && command === 'dev'; const usesContentCollections = hasContentCollectionsConfig(config.srcDir); const prebundleContentRuntime = command === 'dev' && usesContentCollections; + const isTypeGenOnly = command === 'build' || command === 'sync'; const adapterPluginConfig: Partial = { config: cloudflareConfigCustomizer({ @@ -241,6 +242,18 @@ export default function createIntegration({ // include, and esbuildOptions (e.g. loader) entries are respected. const userOptimizeDeps = config.vite?.optimizeDeps; + const cloudflareVitePlugins = cfVitePlugin({ + ...cfPluginConfig, + viteEnvironment: { name: 'ssr' }, + assetsOnly: () => _buildOutput === 'static', + }); + // Avoid starting the Cloudflare dev runtime during type generation. See #16332. + if (isTypeGenOnly) { + for (const plugin of cloudflareVitePlugins) { + plugin.configureServer = undefined; + } + } + updateConfig({ build: { redirects: false, @@ -251,11 +264,7 @@ export default function createIntegration({ ...(prerenderEnvironment === 'node' && command === 'dev' ? [createNodePrerenderPlugin()] : []), - cfVitePlugin({ - ...cfPluginConfig, - viteEnvironment: { name: 'ssr' }, - assetsOnly: () => _buildOutput === 'static', - }), + cloudflareVitePlugins, { name: '@astrojs/cloudflare:cf-imports', enforce: 'pre', @@ -271,6 +280,10 @@ export default function createIntegration({ { name: '@astrojs/cloudflare:environment', configEnvironment(environmentName, _options) { + // Avoid dependency optimization during type generation. See #16332. + if (isTypeGenOnly) { + return { optimizeDeps: { noDiscovery: true, include: [] } }; + } const isServerEnvironment = ['astro', 'ssr', 'prerender'].includes( environmentName, ); From 95b933941efedfa07297bf6252b6ef150f2fad30 Mon Sep 17 00:00:00 2001 From: Adam Chalemian Date: Thu, 18 Jun 2026 16:57:54 -0400 Subject: [PATCH 2/2] docs(cloudflare): explain why type-gen runtime skip covers build and sync --- packages/integrations/cloudflare/src/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 6d8187b06089..5d629aadfb70 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -174,7 +174,7 @@ export default function createIntegration({ const needsImagesBindingForDev = isCompile && command === 'dev'; const usesContentCollections = hasContentCollectionsConfig(config.srcDir); const prebundleContentRuntime = command === 'dev' && usesContentCollections; - const isTypeGenOnly = command === 'build' || command === 'sync'; + const isTypeGenPhase = command === 'build' || command === 'sync'; const adapterPluginConfig: Partial = { config: cloudflareConfigCustomizer({ @@ -247,8 +247,11 @@ export default function createIntegration({ viteEnvironment: { name: 'ssr' }, assetsOnly: () => _buildOutput === 'static', }); - // Avoid starting the Cloudflare dev runtime during type generation. See #16332. - if (isTypeGenOnly) { + // `sync` and `build` both run type generation (build via its internal sync + // pass), which creates a temporary Vite server and fires `configureServer` + // the hook that boots the Cloudflare/workerd runtime. Drop it in both so + // type generation doesn't pay that startup cost. See #16332. + if (isTypeGenPhase) { for (const plugin of cloudflareVitePlugins) { plugin.configureServer = undefined; } @@ -280,8 +283,8 @@ export default function createIntegration({ { name: '@astrojs/cloudflare:environment', configEnvironment(environmentName, _options) { - // Avoid dependency optimization during type generation. See #16332. - if (isTypeGenOnly) { + // Skip dependency pre-bundling during type generation (see `isTypeGenPhase` above). + if (isTypeGenPhase) { return { optimizeDeps: { noDiscovery: true, include: [] } }; } const isServerEnvironment = ['astro', 'ssr', 'prerender'].includes(