Repository navigation
fix(sync): skip adapter configureServer hooks during type generation #16587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "astro": patch | ||
| --- | ||
|
|
||
| Skips adapter `configureServer` hooks and per-environment dependency pre-bundling during the temporary Vite server used by `astro build` for type generation. The temp server only resolves virtual modules — it never serves HTTP requests — so starting adapter runtimes (e.g. miniflare/workerd via `@astrojs/cloudflare`) and pre-bundling adapter `optimizeDeps.include` lists were both unnecessary. On a representative project this reduces the “Types Generated” phase from ~3.6 s to ~125 ms. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is the correct fix. For example, in your comment you say that some Astro plugins rely on this hook, but what if there are other plugins (integrations, user, etc.) that need this hook? I believe this fix should live in the Cloudflare adapter. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,13 +234,45 @@ async function createTempViteServer( | |
| { dev: true }, | ||
| ); | ||
|
|
||
| // Disable dependency optimization for all environments. The temp server only needs | ||
| // to resolve virtual modules for type generation, not pre-bundle dependencies. | ||
| // Setting this per-environment ensures adapter plugins (e.g. Cloudflare) see the | ||
| // flag and skip injecting their own optimizeDeps.include lists. | ||
| const noOptimize = { optimizeDeps: { noDiscovery: true, include: [] } }; | ||
|
|
||
| const tempViteServer = await createServer( | ||
| await createVite( | ||
| { | ||
| server: { middlewareMode: true, hmr: false, watch: null, ws: false }, | ||
| optimizeDeps: { noDiscovery: true }, | ||
| ssr: { external: [] }, | ||
| logLevel: 'silent', | ||
| environments: { | ||
| client: noOptimize, | ||
| ssr: noOptimize, | ||
| astro: noOptimize, | ||
| prerender: noOptimize, | ||
| }, | ||
| plugins: [ | ||
| // Strip `configureServer` hooks from non-Astro plugins. The temp | ||
| // server is only used to resolve modules for type generation — it | ||
| // never serves HTTP requests. Removing these hooks prevents adapter | ||
| // plugins from starting heavy runtimes (e.g. miniflare/workerd for | ||
| // Cloudflare). Astro's own plugins (prefixed with `astro:`) are | ||
| // preserved because some rely on configureServer to set up state | ||
| // needed by their other hooks. | ||
| { | ||
| name: 'astro:sync:strip-server-hooks', | ||
| enforce: 'pre', | ||
| configResolved(config) { | ||
| for (const plugin of config.plugins) { | ||
| if (plugin.configureServer && !plugin.name.startsWith('astro:')) { | ||
| delete plugin.configureServer; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use |
||
| } | ||
| } | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| routesList, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow this guide to create a changeset https://contribute.docs.astro.build/docs-for-code-changes/changesets/#tips-and-examples