Fix SSR routes broken by dynamic prerendered routes with Node prerender environment#16562
Conversation
🦋 Changeset detectedLatest commit: 8df96dd The changes in this PR will be included in the next version bump. This PR includes changesets to release 435 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 |
| const match = matchRoute(pathname, routesList); | ||
|
|
||
| if (!matches.some((route) => route.prerender)) { | ||
| if (!match?.prerender) { |
There was a problem hiding this comment.
I’m not super familiar with this code, but isn’t the current logic intentional: any prerendered route that matches would win over dynamic ones? (As it would when deployed.)
I don’t know how this interacts with getStaticPaths() though — does virtual:astro:routes already include that data?
There was a problem hiding this comment.
Yeah I think you're right.
There was a problem hiding this comment.
Ok, reverted this part. New logic is that the prerender handler only handles prerender (as it should) rather than changing route matching logic.
…endered Instead of switching from matchAllRoutes to matchRoute (which could skip prerendered routes when an SSR route has higher specificity), keep the broad matchAllRoutes gate but add a fallback mechanism: handleRequest now returns a boolean indicating whether it handled the request, and accepts a prerenderOnly option. When the prerender handler's best match is an SSR route, it returns false and the middleware falls through to the SSR handler.
1ecd56b to
2e23fec
Compare
delucis
left a comment
There was a problem hiding this comment.
Small internal docs suggestion so we keep track of the new behaviour of handleRequest()
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
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)) | [`6.3.1` → `6.3.2`](https://renovatebot.com/diffs/npm/astro/6.3.1/6.3.2) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v6.3.2`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#632) [Compare Source](https://github.com/withastro/astro/compare/astro@6.3.1...astro@6.3.2) ##### Patch Changes - [#​16675](withastro/astro#16675) [`11d4592`](withastro/astro@11d4592) Thanks [@​ascorbic](https://github.com/ascorbic)! - Fixes a regression where `Astro.cache` was `undefined` when `experimental.cache` was not configured. The previous documented behavior is for `Astro.cache` to always be defined as a no-op shim: `cache.set()` warns once, `cache.invalidate()` throws and `cache.enabled` can be used to gate. This allows library and user code can call cache methods without conditional checks. The cache provider registration was being gated at the call site on `experimental.cache` being configured, which meant the disabled shim branch inside the provider was unreachable and the `Astro.cache` getter was never attached to the context. - [#​16691](withastro/astro#16691) [`0f0a4ce`](withastro/astro@0f0a4ce) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes `HTMLElement is not defined` error during HMR when using components with client-side scripts (e.g. Starlight `<Tabs>`) and the Cloudflare adapter - [#​16562](withastro/astro#16562) [`07529ec`](withastro/astro@07529ec) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes non-prerendered routes failing when a dynamic prerendered route exists in the same project with `prerenderEnvironment: 'node'` - [#​16638](withastro/astro#16638) [`272185b`](withastro/astro@272185b) Thanks [@​ematipico](https://github.com/ematipico)! - Fixes a bug where the Astro compiler wasn't freed at the end of the build. After the fix, the memory used by the compiler is now correctly freed at the end of the build. - [#​16544](withastro/astro#16544) [`d365c97`](withastro/astro@d365c97) Thanks [@​matthewp](https://github.com/matthewp)! - Tightens `isRemotePath()` to reject control characters after a leading slash and fixes the dev image endpoint origin check - [#​16685](withastro/astro#16685) [`889e748`](withastro/astro@889e748) Thanks [@​farrosfr](https://github.com/farrosfr)! - Improve validation messages for `security.csp.directives` when `script-src` or `style-src` are incorrectly placed in the `directives` array. - [#​16605](withastro/astro#16605) [`772f13a`](withastro/astro@772f13a) Thanks [@​rururux](https://github.com/rururux)! - Fixes `assetsPrefix` not being available on `build` from `astro:config/server`. - [#​16556](withastro/astro#16556) [`f38dec7`](withastro/astro@f38dec7) Thanks [@​matthewp](https://github.com/matthewp)! - Rejects double-encoded URL paths with a 400 response instead of silently falling back to partial decoding - [#​16659](withastro/astro#16659) [`38bcb25`](withastro/astro@38bcb25) Thanks [@​jsparkdev](https://github.com/jsparkdev)! - Fixes `&` characters appearing as raw entity strings (e.g. `&#​38;`) in `<meta>` tags when viewed in link previews or raw HTML. - Updated dependencies \[[`d365c97`](withastro/astro@d365c97), [`9256345`](withastro/astro@9256345)]: - [@​astrojs/internal-helpers](https://github.com/astrojs/internal-helpers)@​0.9.1 - [@​astrojs/markdown-remark](https://github.com/astrojs/markdown-remark)@​7.1.2 </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](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNzAuMjAiLCJ1cGRhdGVkSW5WZXIiOiI0My4xNzAuMjAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbXX0=-->
Fixes #16553
Changes
cloudflare:workers) failing when a dynamic prerendered route like[page].astroexists in the same project withprerenderEnvironment: 'node'.matchAllRoutes(), which returns every route matching a pathname. A request to/ssrwould match bothssr.astro(non-prerendered) and[page].astro(prerendered), and since one match was prerendered, the request was incorrectly routed to the Node handler. Replaced withmatchRoute(), which returns only the highest-priority match.Testing
[page].astrowithgetStaticPaths) to the existingprerender-node-envfixture. The existing "renders SSR page through workerd" test now exercises this scenario.Docs