Visitar URL original
Pre-bundle renderer server entrypoints and the default logger to stop Cloudflare dev crashes by matthewp · Pull Request #17945 · withastro/astro · GitHub
Skip to content

Pre-bundle renderer server entrypoints and the default logger to stop Cloudflare dev crashes - #17945

Merged
matthewp merged 9 commits into
mainfrom
fix/17921-optimizedeps-workerd-crash
Sep 10, 2026
Merged

matthewp merged 9 commits into
mainfrom
fix/17921-optimizedeps-workerd-crash

Conversation

@matthewp

@matthewp matthewp commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Cloudflare dev servers crash when the dep optimizer discovers a framework's server renderer or the default logger mid-request: the optimizer rewrites deps_ssr/ chunks while workerd still references the previous bundle. The adapter now pre-bundles renderer server entrypoints and astro/logger/console up front, so the optimizer never re-runs once workerd has started.

Testing

No unit tests added; covered by the existing dev flows. The reported crash reproduced 3/3 on the reporter's stack before the fix and no longer reproduces after; both deps appear in the first optimization pass (deps_ssr/_metadata.json).

Docs

No docs update needed; dev-mode reliability fix with no user-facing API change.

…ogger 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
@changeset-bot

changeset-bot Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 53b66a8

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 pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) labels Sep 8, 2026
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.
@codspeed

codspeed Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 14.61%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 (👁 1) regressed benchmark
✅ 20 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
👁 many-components (markHTMLString, isHTMLString, validateProps) 9.6 ms 11.3 ms -14.61%

Comparing fix/17921-optimizedeps-workerd-crash (53b66a8) with main (2fc7ce9)

Open in CodSpeed

…flare 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.
…pter, 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
…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
… 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.
@matthewp matthewp changed the title Pre-bundle renderer server entrypoints and the default logger to stop Cloudflare dev crashes Pre-bundle the default console logger to prevent Cloudflare dev crashes Sep 9, 2026
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
@github-actions github-actions Bot removed pkg: astro Related to the core `astro` package (scope) docs pr labels Sep 9, 2026
@matthewp matthewp changed the title Pre-bundle the default console logger to prevent Cloudflare dev crashes Pre-bundle renderer server entrypoints and the default logger to stop Cloudflare dev crashes Sep 9, 2026
…al 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
@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label Sep 9, 2026
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.
@matthewp
matthewp marked this pull request as ready for review September 9, 2026 16:27
@matthewp
matthewp merged commit 750b4db into main Sep 10, 2026
29 checks passed
@matthewp
matthewp deleted the fix/17921-optimizedeps-workerd-crash branch September 10, 2026 12:19
@astrobot-houston astrobot-houston mentioned this pull request Sep 9, 2026
dadezzz pushed a commit to dadezzz/university_notes that referenced this pull request Sep 20, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [astro](https://astro.build) ([source](https://github.com/withastro/astro/tree/HEAD/packages/astro)) | [`7.3.2` → `7.3.3`](https://renovatebot.com/diffs/npm/astro/7.3.2/7.3.3) | ![age](https://developer.mend.io/api/mc/badges/age/npm/astro/7.3.3?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/astro/7.3.2/7.3.3?slim=true) |

---

### Release Notes

<details>
<summary>withastro/astro (astro)</summary>

### [`v7.3.3`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#733)

[Compare Source](https://github.com/withastro/astro/compare/astro@7.3.2...astro@7.3.3)

##### Patch Changes

- [#&#8203;17651](withastro/astro#17651) [`504333c`](withastro/astro@504333c) Thanks [@&#8203;sxzz](https://github.com/sxzz)! - Refactors internal version handling to use a smaller, ESM-native dependency

- [#&#8203;17942](withastro/astro#17942) [`0bc5715`](withastro/astro@0bc5715) Thanks [@&#8203;matthewp](https://github.com/matthewp)! - Returns appropriate 400 and 404 responses from the image endpoint for invalid and missing local image paths

- [#&#8203;17700](withastro/astro#17700) [`b2222fc`](withastro/astro@b2222fc) Thanks [@&#8203;winklemad](https://github.com/winklemad)! - Fixes `Astro.preferredLocaleList` returning an empty list when a locale is configured with the object form (`{ path, codes }`) and the browser sends the code with different casing or an underscore, such as `en-US` matching a configured `en-us`

- [#&#8203;17941](withastro/astro#17941) [`394ff79`](withastro/astro@394ff79) Thanks [@&#8203;matthewp](https://github.com/matthewp)! - Fixes `astro preview --ignore-lock` (and `astro dev --ignore-lock`) being refused when run from an AI agent environment. The flag now starts the server in the foreground instead of erroring, since agent detection only inferred background mode and was never explicitly requested. An explicit `--background` combined with `--ignore-lock` still errors.

- [#&#8203;17928](withastro/astro#17928) [`3277927`](withastro/astro@3277927) Thanks [@&#8203;ArmandPhilippot](https://github.com/ArmandPhilippot)! - Fixes TypeScript autocompletion for `getImage()` to suggest all available predefined options.

- [#&#8203;17928](withastro/astro#17928) [`3277927`](withastro/astro@3277927) Thanks [@&#8203;ArmandPhilippot](https://github.com/ArmandPhilippot)! - Fixes a type error in `getImage()` options that allowed passing both `widths` and `densities` at the same time.

- [#&#8203;17857](withastro/astro#17857) [`2637ed1`](withastro/astro@2637ed1) Thanks [@&#8203;Princesseuh](https://github.com/Princesseuh)! - Improves rendering performance

- [#&#8203;17943](withastro/astro#17943) [`2fc7ce9`](withastro/astro@2fc7ce9) Thanks [@&#8203;matthewp](https://github.com/matthewp)! - Fixes a WebAssembly error when importing `astro:actions` in tests that run under `@cloudflare/vitest-pool-workers`

- [#&#8203;18018](withastro/astro#18018) [`1b5a234`](withastro/astro@1b5a234) Thanks [@&#8203;astro-factory](https://github.com/apps/astro-factory)! - Fixes trailing-slash redirect response body pointing to the incoming URL instead of the redirect target. The `location` header was correct, but the HTML body (`<meta http-equiv="refresh">`, `<title>`, and `<a>` tag) contained the original request path without the trailing-slash correction or query string.

- [#&#8203;17905](withastro/astro#17905) [`eaf70fa`](withastro/astro@eaf70fa) Thanks [@&#8203;SudoDevStudio](https://github.com/SudoDevStudio)! - Fixes custom dev toolbar apps losing their UI after client-side navigation with `<ClientRouter />`.

- [#&#8203;18011](withastro/astro#18011) [`558b301`](withastro/astro@558b301) Thanks [@&#8203;astro-factory](https://github.com/apps/astro-factory)! - Fixes prerendered Cloudflare pages rendering as `[object Object]` when `nodejs_compat` is enabled in `wrangler.toml`

- [#&#8203;17944](withastro/astro#17944) [`ba08e35`](withastro/astro@ba08e35) Thanks [@&#8203;matthewp](https://github.com/matthewp)! - Fixes a regression in `astro dev` where writes outside the module graph (for example, `@astrojs/cloudflare`'s `.wrangler/state` files) invalidated the middleware on every request, causing repeated SSR reloads. Such writes no longer invalidate the middleware.

- [#&#8203;17531](withastro/astro#17531) [`ae837db`](withastro/astro@ae837db) Thanks [@&#8203;danilloestrela](https://github.com/danilloestrela)! - Updates `svgo` to `4.0.2` to resolve a security advisory

- [#&#8203;17953](withastro/astro#17953) [`dbbf10e`](withastro/astro@dbbf10e) Thanks [@&#8203;astro-factory](https://github.com/apps/astro-factory)! - Fixes a one-time page reload shortly after the first load on cold dev-server starts when a project has framework components imported from MDX content entries. MDX files are now included in the dev dependency pre-bundling scan, so their framework dependencies are bundled up front instead of being discovered (and reloaded for) at runtime.

- [#&#8203;17955](withastro/astro#17955) [`4e8ad9a`](withastro/astro@4e8ad9a) Thanks [@&#8203;matthewp](https://github.com/matthewp)! - Improves dev server startup time. The content config and dev server app module graphs now begin compiling during server creation without blocking the server from listening. Request handling waits for the shared setup result when needed, cutting `astro dev` ready time by roughly a third on projects with a content config.

- [#&#8203;17960](withastro/astro#17960) [`9838049`](withastro/astro@9838049) Thanks [@&#8203;Chy-Zaber-Bin-Zahid](https://github.com/Chy-Zaber-Bin-Zahid)! - Improves the diagnostics of some Astro errors.

- [#&#8203;17998](withastro/astro#17998) [`0e5478d`](withastro/astro@0e5478d) Thanks [@&#8203;astro-factory](https://github.com/apps/astro-factory)! - Fixes SVG `<style>` elements nested inside `<defs>` or other container elements not being hashed for CSP

- [#&#8203;17994](withastro/astro#17994) [`80f9f1d`](withastro/astro@80f9f1d) Thanks [@&#8203;astro-factory](https://github.com/apps/astro-factory)! - Fixes `experimental.incrementalBuild` restoring pages with stale CSS after a preprocessor partial changes or missing original images referenced by restored pages

- [#&#8203;17889](withastro/astro#17889) [`8ae6b46`](withastro/astro@8ae6b46) Thanks [@&#8203;ajfAfg](https://github.com/ajfAfg)! - Fixes a bug where the dev server stripped the configured `base` from URLs that only share a prefix with it. With `base: '/s'`, requests to `/src/...` were rewritten to `/rc/...` and failed, breaking those pages during development.

- [#&#8203;17980](withastro/astro#17980) [`cfccafa`](withastro/astro@cfccafa) Thanks [@&#8203;gameroman](https://github.com/gameroman)! - Improves JSDoc for fonts api

- [#&#8203;17953](withastro/astro#17953) [`dbbf10e`](withastro/astro@dbbf10e) Thanks [@&#8203;astro-factory](https://github.com/apps/astro-factory)! - Fixes CSS HMR for framework components rendered through content entries after `ClientRouter` navigation

- [#&#8203;17970](withastro/astro#17970) [`0b4dc3a`](withastro/astro@0b4dc3a) Thanks [@&#8203;matthewp](https://github.com/matthewp)! - Improves serialization of transition animation values in generated CSS

- [#&#8203;17999](withastro/astro#17999) [`30ef3cb`](withastro/astro@30ef3cb) Thanks [@&#8203;astro-factory](https://github.com/apps/astro-factory)! - Fixes content collection HMR not updating prerendered pages when an adapter enables a separate prerender environment (e.g. `@astrojs/cloudflare` with `prerenderEnvironment: 'node'`)

- [#&#8203;18002](withastro/astro#18002) [`312ab49`](withastro/astro@312ab49) Thanks [@&#8203;shoutoutuoadi325](https://github.com/shoutoutuoadi325)! - Fixes redirect targets being corrupted when a dynamic route parameter value contains `$` replacement patterns like `$&`

- [#&#8203;17937](withastro/astro#17937) [`e294953`](withastro/astro@e294953) Thanks [@&#8203;matthewp](https://github.com/matthewp)! - Fixes a bug where the `glob()` content loader kept stale entries in the data store after the last file in a collection was deleted. Empty collections are now pruned correctly, and the file watcher is registered in dev so the first file added to an empty collection is picked up without a restart.

- [#&#8203;17945](withastro/astro#17945) [`750b4db`](withastro/astro@750b4db) Thanks [@&#8203;matthewp](https://github.com/matthewp)! - Pre-bundles renderer server entrypoints and the default console logger during dev so they are included in the initial optimization pass, preventing a mid-request re-optimization that could crash the dev server on Cloudflare (workerd).

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMDMuMiIsInVwZGF0ZWRJblZlciI6IjQ0LjEwMy4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
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) pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants