fix(sync): skip adapter configureServer hooks during type generation#16587
Open
adamchal wants to merge 1 commit intowithastro:mainfrom
Open
fix(sync): skip adapter configureServer hooks during type generation#16587adamchal wants to merge 1 commit intowithastro:mainfrom
adamchal wants to merge 1 commit intowithastro:mainfrom
Conversation
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
🦋 Changeset detectedLatest commit: 1312a08 The changes in this PR will be included in the next version bump. 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.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.@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.