feat: advanced routing types and config gaps#16723
Conversation
🦋 Changeset detectedLatest commit: 71753fd The changes in this PR will be included in the next version bump. This PR includes changesets to release 421 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 |
ematipico
left a comment
There was a problem hiding this comment.
This PR actually needs docs. The fetchFile thing isn't documented
https://docs.astro.build/en/reference/experimental-flags/advanced-routing/#adding-custom-logic
|
@ematipico docs added at withastro/docs#13890 |
| fetchFile: z | ||
| .string() | ||
| .nullable() | ||
| .optional() | ||
| .default('app'), |
There was a problem hiding this comment.
This should go under experimental.advancedRouting. We can't add new config fields like this, especially inside a patch.
There was a problem hiding this comment.
Yeah, we used to not do it that way, because would have flags like --experimental-* so it didn't make sense for experimental config to be anything more than booleans since the CLI could not convey this. BUt we stopped using CLI flags. Anyways, just an explanation for why I did it this way.
Will change to:
experimental: {
advancedRouting: {
fetchFile: ...
}
}There was a problem hiding this comment.
I know, I don't think we always added experimental CLI flags anymore
There was a problem hiding this comment.
This is changed now. Now a union of boolean or an object with this option.
| 'astro': patch | ||
| --- | ||
|
|
||
| Adds missing types and config for advanced routing: `Fetchable` export, `FetchState.response`, `App.Providers` for typed context providers, and `fetchFile` config option. Fixes Hono `cache()` middleware to follow the standard wrapper pattern. |
There was a problem hiding this comment.
nit: should this be two separate changesets? It seems the two sentences are unrelated and it might be easier to scan in the changelog if they are not in the same file.
There was a problem hiding this comment.
Yeah good point, i'll split it out into separate ones for each new thing.
|
This is ready for another review. |
ArmandPhilippot
left a comment
There was a problem hiding this comment.
Thanks, the changesets looks to me. The config.ts file as well for the content.
But, I had a doubt seeing the ### heading. I checked how this was done before and for experimental CSP, we were using a @name experimental.advancedRouting.fetchFile block, not a Markdown heading. So, I suggested changes for this.
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
|
| 📦 Package | 🔒 Before | 🔓 After |
|---|---|---|
| @clack/core | trusted-with-provenance | none |
| @clack/prompts | trusted-with-provenance | none |
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
* feat: fill in missing advanced routing types and config * test: add tests for state.response and context providers * chore: add changeset * Review comments * Update packages/astro/src/types/public/config.ts Co-authored-by: Armand Philippot <git@armand.philippot.eu> * Update packages/astro/src/types/public/config.ts Co-authored-by: Armand Philippot <git@armand.philippot.eu> --------- Co-authored-by: Armand Philippot <git@armand.philippot.eu>
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.3` → `6.3.5`](https://renovatebot.com/diffs/npm/astro/6.3.3/6.3.5) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v6.3.5`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#635) [Compare Source](https://github.com/withastro/astro/compare/astro@6.3.4...astro@6.3.5) ##### Patch Changes - [#​16771](withastro/astro#16771) [`07c8805`](withastro/astro@07c8805) Thanks [@​ematipico](https://github.com/ematipico)! - Fixes `position` prop on `<Image>` and `<Picture>` components breaking Content Security Policy (CSP). - [#​16593](withastro/astro#16593) [`50924ce`](withastro/astro@50924ce) Thanks [@​yanthomasdev](https://github.com/yanthomasdev)! - Improves error messages with more consistent and correct writing. - [#​16757](withastro/astro#16757) [`5d661cd`](withastro/astro@5d661cd) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes dev server serving stale content when SSR-only modules change (e.g. `.astro` files outside the project root in a monorepo, or dynamically imported components). Previously, the `astro:hmr-reload` plugin returned an empty array after detecting SSR-only module changes, which prevented Vite's `updateModules` from propagating the invalidation to the SSR module runner. The runner's evaluated module cache stayed stale, so subsequent requests continued returning old content. Now the plugin returns the SSR-only modules so Vite can process them through `updateModules`, which properly invalidates the module runner's cache and ensures fresh content on the next request. ### [`v6.3.4`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#634) [Compare Source](https://github.com/withastro/astro/compare/astro@6.3.3...astro@6.3.4) ##### Patch Changes - [#​16723](withastro/astro#16723) [`0f10bfe`](withastro/astro@0f10bfe) Thanks [@​matthewp](https://github.com/matthewp)! - Adds `fetchFile` option to `experimental.advancedRouting` to customize or disable the entrypoint file ```js export default defineConfig({ experimental: { advancedRouting: { fetchFile: 'fetch.ts', }, }, }); ``` - [#​16723](withastro/astro#16723) [`0f10bfe`](withastro/astro@0f10bfe) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes Hono `cache()` middleware to follow the standard wrapper pattern - [#​16723](withastro/astro#16723) [`0f10bfe`](withastro/astro@0f10bfe) Thanks [@​matthewp](https://github.com/matthewp)! - Adds `App.Providers` interface for typing custom context providers on `Astro` and `ctx` ```ts declare namespace App { interface Providers { oauth: import('./lib/oauth').OAuthSession; } } ``` - [#​16723](withastro/astro#16723) [`0f10bfe`](withastro/astro@0f10bfe) Thanks [@​matthewp](https://github.com/matthewp)! - Adds `FetchState.response` property, set automatically after `pages()` or `middleware()` completes ```ts const response = await middleware(state, (s) => pages(s)); console.log(state.response === response); // true ``` - [#​16723](withastro/astro#16723) [`0f10bfe`](withastro/astro@0f10bfe) Thanks [@​matthewp](https://github.com/matthewp)! - Adds `Fetchable` type export for typing the advanced routing entrypoint ```ts import type { Fetchable } from 'astro'; export default { async fetch(request) { return new Response('ok'); }, } satisfies Fetchable; ``` - [#​16572](withastro/astro#16572) [`4a5a077`](withastro/astro@4a5a077) Thanks [@​DORI2001](https://github.com/DORI2001)! - Suppresses `[WARN] Vite warning: unused imports from "@​astrojs/internal-helpers/remote"` during prerender builds. The package is now bundled alongside `astro` in the prerender environment, matching how it is handled in the SSR environment. - [#​16756](withastro/astro#16756) [`b6ee23d`](withastro/astro@b6ee23d) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes styles from Markdoc/MDX custom components not being extracted to `<head>` in the dev server when using the Cloudflare adapter with `prerenderEnvironment: 'node'` and rendering content through a wrapper component. - [#​16747](withastro/astro#16747) [`904d19a`](withastro/astro@904d19a) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes Astro action requests failing in `astro dev` when using the Cloudflare adapter with `prerenderEnvironment: 'node'` alongside a prerendered catch-all route such as `[...page].astro`. Actions and other SSR POST endpoints now continue to work in dev instead of returning an HTTP 500 error. - [#​16701](withastro/astro#16701) [`3495ce4`](withastro/astro@3495ce4) Thanks [@​demaisj](https://github.com/demaisj)! - Fix `Map` and `Set` instances saved in a content collection being broken when retrieving entries. - [#​16614](withastro/astro#16614) [`fca1c32`](withastro/astro@fca1c32) Thanks [@​Eptagone](https://github.com/Eptagone)! - Fixes `entry.data` type inference when a live collection is configured without a schema. - [#​16661](withastro/astro#16661) [`03b8f7f`](withastro/astro@03b8f7f) Thanks [@​ocavue](https://github.com/ocavue)! - Updates `typescript` to v6. No changes are needed from users. - [#​16681](withastro/astro#16681) [`c22770a`](withastro/astro@c22770a) Thanks [@​dotnetCarpenter](https://github.com/dotnetCarpenter)! - Fixes an issue where SVG images with `width="0"` or `height="0"` incorrectly threw a `NoImageMetadata` error instead of being treated as valid dimensions. </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:eyJjcmVhdGVkSW5WZXIiOiI0My4xODIuMSIsInVwZGF0ZWRJblZlciI6IjQzLjE4Mi4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
Changes
Fetchabletype: Exported fromastroso users can typesrc/app.tswithsatisfies Fetchable.FetchState.response: Set byPagesHandlerandAstroMiddlewareafter rendering so callers can readstate.response.App.Providers: New extendable interface for typing custom context providers onctxandAstro.fetchFileconfig: Lets users rename the entrypoint away fromsrc/app.ts, or setnullto disable.cache()wrapper: Now follows the standard middleware pattern like the other Hono wrappers.Testing
Added 6 unit tests in
test/units/fetch/index.test.ts:state.responseis set afterpages()andmiddleware()provide/resolvelazy creation and cachingfinalizeAllruns finalize for resolved providers, skips unresolved onesDocs
Added here: withastro/docs#13890