Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 67f52c2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 401 packages
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 |
The temp Vite server created by `astro build` for type generation only
resolves virtual modules — it never serves HTTP requests. Adapter
plugins (notably `@cloudflare/vite-plugin` via `@astrojs/cloudflare`)
were still firing `configureServer` and starting heavy runtimes
(miniflare/workerd), and Vite 7's per-environment config meant
`optimizeDeps.noDiscovery` only applied to the `client` environment so
adapters were re-injecting large `optimizeDeps.include` lists into
server environments.
Two changes in `createTempViteServer`:
1. Set `optimizeDeps: { noDiscovery: true, include: [] }` on every
environment (`client`, `ssr`, `astro`, `prerender`).
2. Add an inline `astro:sync:strip-server-hooks` plugin that removes
`configureServer` from non-Astro plugins in `configResolved`.
Astro's own plugins are preserved.
On a representative project this drops the “Types Generated” phase
from ~3.6 s to ~125 ms.
Closes withastro#16332
1312a08 to
67f52c2
Compare
|
I appreciate the PR, but I don't like the bug report. The bug report straight says "this function does this and that". Then, it went straight with the diagnosis and root cause, assuming that it's correct. Please reword the original issue from the user point of view. If you want to add your AI diagnosis, you're more than welcome to do so in a comment. Plus, everything ignores the fact that |
|
@ematipico reworded #16332 from a user pov. I left the AI diagnosis out of the issue as I am trying to think of any regressions that would occur as a result of striping non-Astro server hooks when creating the temp server. It passes CI now, but my only concern is that if someone in the future decides to use the temp server for another purpose, they may assume that it would be identical and run against latent bugs. My (selfish) feeling is that the performance increase in |
|
Thank you @adamchal . You should also reword the PR. It still talks about |
| configResolved(config) { | ||
| for (const plugin of config.plugins) { | ||
| if (plugin.configureServer && !plugin.name.startsWith('astro:')) { | ||
| delete plugin.configureServer; |
There was a problem hiding this comment.
Don't use delete, but assign undefined. 90% of the time, delete is usually incorrect.
There was a problem hiding this comment.
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.
| "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. |
There was a problem hiding this comment.
Follow this guide to create a changeset https://contribute.docs.astro.build/docs-for-code-changes/changesets/#tips-and-examples
|
@ematipico based on your comment:
You are absolutely right. I opened a new PR #16961 to address this issue in the Cloudflare adapter instead of Astro core. |
Changes
astro build,createTempViteServer(inpackages/astro/src/core/sync/index.ts) creates a Vite dev server purely to resolve virtual modules for type generation. The server never handles HTTP requests, but every plugin'sconfigureServerhook still fires — including adapter plugins that start heavy runtimes (notably@astrojs/cloudflare→@cloudflare/vite-plugin→ miniflare/workerd, ~1–3.5 s of overhead).optimizeDeps: { noDiscovery: true }only applies to theclientenvironment under Vite 7's Environment API, so adapters'configEnvironmenthooks re-injected theiroptimizeDeps.includelists intossr/astro/prerenderand forced unnecessary pre-bundling.createTempViteServer:optimizeDeps: { noDiscovery: true, include: [] }for all four environments.astro:sync:strip-server-hooksplugin that removesconfigureServerfrom non-astro:plugins inconfigResolved.Types Generateddrops from ~3.6 s to ~125 ms; total build from ~13 s to ~9.2 s.astro syncwith the Cloudflare adapter #16332.patchforastro).This is the fix astrobot-houston suggested on the issue, applied verbatim.
Testing
pnpm exec astro-scripts test test/astro-sync.test.ts --strip-types— all 9 existing sync tests pass.astro syncwith the Cloudflare adapter #16332 (https://github.com/adamchal/astro-sync-perf): with@astrojs/cloudflareon the adapter,Types Generateddrops from ~2.3 s to ~100 ms and miniflare no longer starts during sync.postinstallmonkey-patch) on a production Astro/Cloudflare site for the past few weeks with no regressions in dev or build.Docs
No user-facing API changes — this is a build-time perf fix. Adapter authors who relied on
configureServerfiring during sync would notice, but that path was unintentional and has no documented contract.