Repository navigation
Commit 750b4db
authored
Pre-bundle renderer server entrypoints and the default logger to stop Cloudflare dev crashes (#17945)
* fix(cloudflare): pre-bundle renderer server entrypoints and default logger in optimizeDeps
Renderer server entrypoints (e.g. @astrojs/svelte/server.js) are imported
lazily through virtual:astro:renderers, which the dep optimizer scan cannot
reach. On Cloudflare (workerd), discovering them mid-request triggers a
re-optimization that rewrites the optimized dep cache while workerd still
references the old chunks, crashing the dev server with a 'file does not
exist' error. Pre-include them for all server environments in
vite-plugin-environment (mirroring how client entrypoints are handled in
container.ts), and add astro/logger/console to the Cloudflare adapter's
include list, since the assets runtime logger setup always imports it.
Fixes #17921
* fix(cloudflare): type updateConfig param in optimizeDeps include test
Annotate the updateConfig callback parameter with
Parameters<HookParameters<'astro:config:setup'>['updateConfig']>[0] to fix
TS7006 (implicit any) that failed the cloudflare package build in CI.
* fix(astro): scope renderer server entrypoint pre-include to the Cloudflare adapter
Pre-including every renderer server entrypoint in optimizeDeps for all server
environments regressed Node dev: pre-bundling renderers that are served
through the transform pipeline duplicates framework modules (duplicate React
'invalid hook call' in view-transitions, @astrojs/vue SSR/dev failures). The
Cloudflare adapter is the only runtime that pre-bundles the entire server
graph and cannot tolerate a mid-request renderer discovery, so gate the
pre-include on settings.adapter.name === '@astrojs/cloudflare'. The adapter
cannot read settings.renderers from its hooks, hence the gate lives in core.
* fix(cloudflare): pre-include renderer server entrypoints from the adapter, not core
Reverts the renderer pre-include in vite-plugin-environment, which
special-cased the Cloudflare adapter by name in core. The adapter now adds
every renderer's serverEntrypoint to its own server-environment
optimizeDeps.include, captured from the renderers exposed by a new generic
astro:config:done hook param (additive, adapter-agnostic). Renderers are only
imported lazily through virtual:astro:renderers, so the optimizer scan cannot
reach them; pre-bundling them up front keeps the optimizer from re-running
mid-request, when workerd still references the previous bundle.
Fixes #17921
* fix(cloudflare): drop the core adapter-name gate; scope renderer pre-include to workerd envs
Commit the vite-plugin-environment revert that removes the Cloudflare
adapter-name gate from core (the previous commit left it in HEAD, so the PR
diff still special-cased an adapter in core). The adapter now owns the whole
renderer pre-include: it adds each renderer's serverEntrypoint to its
server-environment optimizeDeps.include, captured from the renderers exposed
by astro:config:done (passed as a readonly snapshot so integrations cannot
mutate Astro's internal list). The entries are skipped for the prerender
environment when prerenderEnvironment is 'node', where pre-bundling renderers
would duplicate framework modules; only workerd environments get them.
Fixes #17921
* fix(cloudflare): use a platform-agnostic file URL in the optimizeDeps test
The URL-form renderer used a Unix-only file:///tmp/... URL, which made the
adapter's fileURLToPath throw ERR_INVALID_FILE_URL_PATH on Windows and fail
the integrations Windows CI job. Build the URL from import.meta.url so the
path is absolute on every platform.
* fix(cloudflare): pre-bundle the default console logger in optimizeDeps
Per maintainer review: drop the renderer server entrypoint pre-include and the
astro:config:done renderers param it depended on (a public hook change), and
drop the adapter unit tests. The adapter now only pre-bundles
astro/logger/console, which the assets runtime logger setup always imports on
the server but which was missing from the include list; a late discovery
would re-run the optimizer mid-request and crash workerd.
Fixes #17921
* fix(cloudflare): pre-bundle renderer server entrypoints via an internal plugin channel
Restores the renderer server entrypoint pre-include that was removed when the
astro:config:done renderers param was dropped. Instead of the public hook
change, the adapter reads the registered renderers through an internal,
undocumented channel: vite-plugin-renderers now exposes them on its plugin
object, and the adapter's @astrojs/cloudflare:environment plugin reads them in
its Vite config hook (which runs before configEnvironment, so the entries are
available when the server environments' optimizeDeps.include is assembled).
Renderers are pre-bundled alongside astro/logger/console, skipped for the Node
prerender environment.
Fixes #17921
* fix(cloudflare): rename vite config hook param to avoid shadowing
The config hook's parameter shadowed the astro:config:setup hook's config
parameter, failing @typescript-eslint/no-shadow in the Lint job. Rename it to
viteConfig; the internal plugin-channel mechanism is unchanged.1 parent dbbf10e commit 750b4db
3 files changed
Lines changed: 37 additions & 1 deletion
File tree
- .changeset
- packages
- astro/src/vite-plugin-renderers
- integrations/cloudflare/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
| |||
68 | 72 | | |
69 | 73 | | |
70 | 74 | | |
71 | | - | |
| 75 | + | |
72 | 76 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
| |||
326 | 332 | | |
327 | 333 | | |
328 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
329 | 346 | | |
330 | 347 | | |
331 | 348 | | |
| |||
335 | 352 | | |
336 | 353 | | |
337 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
338 | 360 | | |
339 | 361 | | |
340 | 362 | | |
| |||
371 | 393 | | |
372 | 394 | | |
373 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
374 | 400 | | |
375 | 401 | | |
376 | 402 | | |
| |||
0 commit comments