Skip to content

fix(astro): prevent crash when deleting an injected route's entrypoint in dev - #18334

Open
lx3133584 wants to merge 1 commit into
withastro:mainfrom
lx3133584:fix/dev-injected-route-unlink-crash
Open

lx3133584 wants to merge 1 commit into
withastro:mainfrom
lx3133584:fix/dev-injected-route-unlink-crash

Conversation

@lx3133584

Copy link
Copy Markdown

Changes

  • Fix unhandled rejection / server crash in dev mode when an injected route's entrypoint is deleted or renamed (Deleting an injected route's entrypoint in dev crashes the server under @astrojs/cloudflare (unhandled rejection in the routes rebuild) #18325).
  • In dev mode, when createRoutesList() reads route component content for prerender options and encounters ENOENT (e.g. when an integration injected route points to a file that was deleted or renamed during dev), catch the error and log a warning instead of throwing, allowing other routes to continue rebuilding and functioning normally.
  • In rebuildRoutes() within vite-plugin-routes, wrap the route rebuild in a try/catch block to ensure watcher event listeners do not emit unhandled promise rejections.
  • In build mode, missing route entrypoints continue to throw an error as expected.
  • Added a patch changeset for astro.

Fixes #18325

Testing

  • Added unit tests in packages/astro/test/units/routing/manifest.test.ts:
    • in dev mode, does not throw when an injected route entrypoint does not exist
    • in build mode, throws when an injected route entrypoint does not exist
  • Ran all 305 routing unit tests (./node_modules/.bin/astro-scripts test "test/units/routing/*.test.ts" --strip-types) with 100% pass rate.
  • Verified monorepo typecheck passes (pnpm run typecheck).

Docs

Bug fix only; does not change public documentation or API surface.

🤖 Generated with Claude Code

…t in dev

In dev mode, deleting or renaming an injected route's entrypoint caused createRoutesList to reject with ENOENT when reading prerender exports, resulting in an unhandled rejection that crashed the server under adapters without unhandledRejection handlers (such as @astrojs/cloudflare) and halted route updates.

- Catch ENOENT when reading route entrypoint in createRoutesList under dev mode and log a warning instead of throwing.
- Wrap rebuildRoutes in vite-plugin-routes with try/catch to prevent unhandled rejections from file watcher events.
- Added unit tests for missing injected entrypoints in both dev mode and build mode.

Fixes withastro#18325

Co-Authored-By: Claude Code <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4b9993d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Patch

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 Oct 11, 2026
@codspeed

codspeed Bot commented Oct 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 3 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 13 benchmarks have no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

✅ 21 untouched benchmarks


Comparing lx3133584:fix/dev-injected-route-unlink-crash (4b9993d) with main (a85847e)1

Open in CodSpeed

Footnotes

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

This branch has not been deployed

No deployments
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.

Deleting an injected route's entrypoint in dev crashes the server under @astrojs/cloudflare (unhandled rejection in the routes rebuild)

1 participant