Skip to content

fix(sync): skip adapter configureServer hooks during type generation#16587

Open
adamchal wants to merge 1 commit intowithastro:mainfrom
adamchal:fix/sync-skip-adapter-server-hooks
Open

fix(sync): skip adapter configureServer hooks during type generation#16587
adamchal wants to merge 1 commit intowithastro:mainfrom
adamchal:fix/sync-skip-adapter-server-hooks

Conversation

@adamchal
Copy link
Copy Markdown
Contributor

@adamchal adamchal commented May 4, 2026

Changes

  • During astro build, createTempViteServer (in packages/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's configureServer hook still fires — including adapter plugins that start heavy runtimes (notably @astrojs/cloudflare@cloudflare/vite-plugin → miniflare/workerd, ~1–3.5 s of overhead).
  • Additionally, top-level optimizeDeps: { noDiscovery: true } only applies to the client environment under Vite 7's Environment API, so adapters' configEnvironment hooks re-injected their optimizeDeps.include lists into ssr / astro / prerender and forced unnecessary pre-bundling.
  • Two changes in createTempViteServer:
    • Per-environment optimizeDeps: { noDiscovery: true, include: [] } for all four environments.
    • Inline astro:sync:strip-server-hooks plugin that removes configureServer from non-astro: plugins in configResolved.
  • Net effect on a representative project: Types Generated drops from ~3.6 s to ~125 ms; total build from ~13 s to ~9.2 s.
  • Closes [Performance]: Build-time content sync starts miniflare via temp Vite dev server (~1-3.5s overhead) #16332.
  • Changeset added (patch for astro).

This is the fix astrobot-houston suggested on the issue, applied verbatim.

Testing

Docs

No user-facing API changes — this is a build-time perf fix. Adapter authors who relied on configureServer firing during sync would notice, but that path was unintentional and has no documented contract.

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-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 4, 2026

🦋 Changeset detected

Latest 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

@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label May 4, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 4, 2026

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing adamchal:fix/sync-skip-adapter-server-hooks (1312a08) with main (17f1867)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (3f67b84) during the generation of this report, so 17f1867 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

SamyP22

This comment was marked as low quality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance]: Build-time content sync starts miniflare via temp Vite dev server (~1-3.5s overhead)

2 participants