Repository navigation
Fix /_image 500 when catch-all prerendered route is combined with prerenderEnvironment: 'node' - #17349
Conversation
🦋 Changeset detectedLatest commit: 39f0277 The changes in this PR will be included in the next version bump. This PR includes changesets to release 417 packages
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 |
|
I re-confirmed in the repro repo that this is still an issue with the latest releases. |
fkatsuhiro
left a comment
There was a problem hiding this comment.
@astrobot-houston san
It seems you missed changeset file. Could you update this? Thank you!
|
Test coverage: the PR shipped without tests, and the two subtle behaviors it introduces (the skip itself, and how it interacts with the rest of Added in bc00c2d:
Verified both directions: everything passes on this branch, and rebuilding |
49bfebd to
bc00c2d
Compare
|
Thank you @alexanderniebuhr and @matthewp for fixing this one, just a polite ping to see if it can get over the line with a review and merge. 🙏 |
… cloudflare:workers error When `prerenderOnly` is true, `matchRoute` now skips routes with `prerender: false` before importing their components. This prevents the Node prerender environment from trying to import modules that use runtime-specific APIs (e.g. `cloudflare:workers`) which are unavailable in Node. Fixes #17348
The importer was committed from the triage bot's local repro checkout. `/triage/` is gitignored, so the directory does not exist for other checkouts and the dangling lockfile entry breaks frozen-lockfile installs in CI. The source changes in this PR do not touch any dependencies, so the lockfile needs no changes.
The retry that strips `.html`/`index.html` re-ran matching without the prerenderOnly filter, so such requests could still import SSR-only modules (e.g. cloudflare:workers) in the Node prerender environment.
Unit tests pin the two behaviors that had no coverage: prerenderOnly skips non-prerendered routes before their modules are imported, and the filter survives the .html alt-pathname retry. An integration test reproduces #17348 end to end: with prerenderEnvironment 'node' and a prerendered catch-all route, /_image must fall through to workerd instead of importing cloudflare:workers in Node. All three fail against the pre-fix sources.
…ching skipped candidates When matchRoute skips non-prerendered candidates in prerenderOnly mode, falling through to the custom 404 lookup could return a prerendered 404.astro, making the prerender handler render a 404 for requests an SSR route would have handled (/_image, /api/*, actions, server islands). Returning undefined lets handleRequest mark the request as not handled so it falls through to the SSR handler, which does its own full matching. This also stops the spurious NoMatchingStaticPathFound warning that fired for every skipped SSR candidate.
Covers the two review findings: a prerendered custom 404 must not shadow a skipped SSR route (the request falls through to the SSR handler instead), and NoMatchingStaticPathFound is not logged when candidates were skipped in prerenderOnly mode. Also keeps a control test that the 404 fallback still applies when nothing was skipped.
65ac767 to
39f0277
Compare
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.2.0` → `7.2.1`](https://renovatebot.com/diffs/npm/astro/7.2.0/7.2.1) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v7.2.1`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#721) [Compare Source](https://github.com/withastro/astro/compare/[email protected]@7.2.1) ##### Patch Changes - [#​17612](withastro/astro#17612) [`7133730`](withastro/astro@7133730) Thanks [@​thelazylamaGit](https://github.com/thelazylamaGit)! - Fixes CSS hot module replacement after navigating between pages with `ClientRouter` - [#​17628](withastro/astro#17628) [`4ada248`](withastro/astro@4ada248) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes a CSP violation when using both `security.csp` and `experimental.clientPrerender` with `data-astro-prefetch` links. The dynamically injected `<script type="speculationrules">` now uses a static `"source": "document"` approach with a CSS selector, producing a deterministic payload that is hashed and included in the CSP `script-src` directive at build time. - [#​17605](withastro/astro#17605) [`89e4647`](withastro/astro@89e4647) Thanks [@​ashleigh-yeoman](https://github.com/ashleigh-yeoman)! - Fixes middleware HMR not responding to changes in imported modules. Previously, only direct edits to the middleware file would trigger a reload. - [#​17582](withastro/astro#17582) [`bd2c1a5`](withastro/astro@bd2c1a5) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes a regression where content collection `reference()` fields silently accepted entry IDs that don't exist, such as an ID that doesn't match a loader's slugified version of it. Astro now logs an error for references that point to a missing entry after all loaders finish syncing. - [#​17661](withastro/astro#17661) [`97b0cc7`](withastro/astro@97b0cc7) Thanks [@​ArmandPhilippot](https://github.com/ArmandPhilippot)! - Improves Markdown options documentation with links to the Markdown guide and official processors. - [#​17349](withastro/astro#17349) [`4328c73`](withastro/astro@4328c73) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes an issue where requests handled by the dev prerender environment (e.g. `/_image` with `@astrojs/cloudflare`'s `prerenderEnvironment: 'node'`) returned a 500 when a prerendered catch-all route existed, because non-prerendered route modules were imported in an environment where their runtime-specific APIs are unavailable - [#​17603](withastro/astro#17603) [`722eed6`](withastro/astro@722eed6) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes `<video>` and `<audio>` elements being non-functional after navigating via view transitions (`<ClientRouter />`) - [#​17616](withastro/astro#17616) [`3a890d2`](withastro/astro@3a890d2) Thanks [@​lazerg](https://github.com/lazerg)! - Fixes `experimental.incrementalBuild` re-rendering unchanged routes that import more than one asset. The route's dependency hash depended on the order the assets finished building, so two builds of identical sources could produce different hashes. The hash is now based on the file name each asset resolves to. - [#​17547](withastro/astro#17547) [`fba468c`](withastro/astro@fba468c) Thanks [@​dmgawel](https://github.com/dmgawel)! - Improves `getCollection()` and `getEntry()` performance for entries without local image references - [#​17602](withastro/astro#17602) [`16e0d9d`](withastro/astro@16e0d9d) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes a build error caused by hash collisions in generated content collection image import identifiers </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:eyJjcmVhdGVkSW5WZXIiOiI0NC4xNy4xIiwidXBkYXRlZEluVmVyIjoiNDQuMTcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
Closes #17348
Changes
/_image),matchRoutenow skips routes withprerender: falsebefore importing their component modules. Previously,/_image's component (@astrojs/cloudflare/image-transform-endpoint) was eagerly imported in the Node prerender environment, where its top-levelimport { env } from 'cloudflare:workers'fails. A prerendered catch-all like[...slug].astrowas enough to trigger this path becausematchAllRoutesreturns it as a candidate for/_image, causing the broad prerender gate inplugin.tsto invoke the prerender handler for the request.prerenderOnlyflag fromhandleRequestthroughdevMatchintomatchRouteto carry the filtering down to the right place.Testing
prerenderEnvironment: 'node', a catch-all prerendered route, and the Cloudflare image endpoint together. Existing tests (dev-image-endpoint.test.ts,prerender-node-env.test.ts) continue to pass. The fix was verified manually by the issue reporter.Docs