Repository navigation
Conversation
…d response errors Adds a `hint` to six request-handling errors that had none, so the dev overlay and CLI show a next step and a docs link instead of only the message. Claude-Session: https://claude.ai/code/session_01UVwZZjkMttKwiVX4Zhvkmi
🦋 Changeset detectedLatest commit: af3f55d 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 |
| name: 'ResponseSentError', | ||
| title: 'Unable to set response.', | ||
| message: 'The response has already been sent to the browser and cannot be altered.', | ||
| hint: 'When HTML streaming is enabled, set cookies, headers, and the status code, or call `Astro.redirect()`, in the page frontmatter or in middleware before any HTML is rendered, not inside a child component. See https://docs.astro.build/en/guides/on-demand-rendering/#html-streaming for more information.', |
There was a problem hiding this comment.
I don't understand the message. Can you reword it?
There was a problem hiding this comment.
Reworded to one plain sentence about where cookies, headers, status, and redirects must be set. Pushed in 29ad9a7.
There was a problem hiding this comment.
I still don't understand what the hint is trying to suggest....
There was a problem hiding this comment.
Fair enough. I could not make it clearer without restating the message, so I dropped it. The PR is now just the redirect message and the rewrite hint.
| title: "The middleware didn't return a `Response`.", | ||
| message: | ||
| 'Make sure your middleware returns a `Response` object, either directly or by returning the `Response` from calling the `next` function.', | ||
| hint: 'This usually happens when a code path in your middleware neither calls `next()` nor returns a `Response`, for example a condition that only returns in one branch. See https://docs.astro.build/en/guides/middleware/ for more information.', |
There was a problem hiding this comment.
This doesn't add any value that the message doesn't do already.
There was a problem hiding this comment.
Agreed, removed.
| name: 'MiddlewareNotAResponse', | ||
| title: 'The middleware returned something that is not a `Response` object.', | ||
| message: 'Any data returned from middleware must be a valid `Response` object.', | ||
| hint: 'To share data with your pages and endpoints, store it in `context.locals` instead of returning it. See https://docs.astro.build/en/guides/middleware/#storing-data-in-contextlocals for more information.', |
There was a problem hiding this comment.
I don't think that's the correct hint here.
There was a problem hiding this comment.
Removed.
| title: 'The endpoint did not return a `Response`.', | ||
| message: | ||
| 'An endpoint must return either a `Response`, or a `Promise` that resolves with a `Response`.', | ||
| hint: 'Wrap plain values in a `Response`, for example with `Response.json()` or `new Response()`. See https://docs.astro.build/en/guides/endpoints/#server-endpoints-api-routes for more information.', |
There was a problem hiding this comment.
Again, it doesn't add additional value
There was a problem hiding this comment.
Agreed, removed.
| export const RedirectWithNoLocation = { | ||
| name: 'RedirectWithNoLocation', | ||
| title: 'A redirect must be given a location with the `Location` header.', | ||
| hint: 'Use `Astro.redirect()` to create redirects, or add a `Location` header to the returned `Response`. See https://docs.astro.build/en/reference/api-reference/#redirect for more information.', |
There was a problem hiding this comment.
Moved it to message and dropped the hint.
| title: 'Cannot use `Astro.rewrite()` after the request body has been read.', | ||
| message: | ||
| '`Astro.rewrite()` cannot be used if the request body has already been read. If you need to read the body, first clone the request.', | ||
| hint: 'Read the body from a clone, for example `await Astro.request.clone().formData()`, and then call `Astro.rewrite()`. See https://docs.astro.build/en/reference/api-reference/#rewrite for more information.', |
There was a problem hiding this comment.
Incorrect hint. This assumes users want to use formData but that's not always the case
There was a problem hiding this comment.
Reworded so it does not assume a body format: read the body from Astro.request.clone() so the original request can still be rewritten.
Drops the middleware and endpoint hints, gives the redirect error a message instead of a hint, and rewords the rewrite and response hints per review. Claude-Session: https://claude.ai/code/session_01JbhX1Tg8qVicVmKWtxg25t
Reviewer could not follow it, and it cannot be made clearer without restating the message. Claude-Session: https://claude.ai/code/session_011p2GHqV2tXFD7FjTebaWJm
There was a problem hiding this comment.
Just a generic "improved some astro diagnostics" (correctly worded) it's enough: https://contribute.docs.astro.build/docs-for-code-changes/changesets/#tips-and-examples
There was a problem hiding this comment.
Done: "Improves the diagnostics of some Astro errors."
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) |  |  | --- ### 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 - [#​17651](withastro/astro#17651) [`504333c`](withastro/astro@504333c) Thanks [@​sxzz](https://github.com/sxzz)! - Refactors internal version handling to use a smaller, ESM-native dependency - [#​17942](withastro/astro#17942) [`0bc5715`](withastro/astro@0bc5715) Thanks [@​matthewp](https://github.com/matthewp)! - Returns appropriate 400 and 404 responses from the image endpoint for invalid and missing local image paths - [#​17700](withastro/astro#17700) [`b2222fc`](withastro/astro@b2222fc) Thanks [@​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` - [#​17941](withastro/astro#17941) [`394ff79`](withastro/astro@394ff79) Thanks [@​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. - [#​17928](withastro/astro#17928) [`3277927`](withastro/astro@3277927) Thanks [@​ArmandPhilippot](https://github.com/ArmandPhilippot)! - Fixes TypeScript autocompletion for `getImage()` to suggest all available predefined options. - [#​17928](withastro/astro#17928) [`3277927`](withastro/astro@3277927) Thanks [@​ArmandPhilippot](https://github.com/ArmandPhilippot)! - Fixes a type error in `getImage()` options that allowed passing both `widths` and `densities` at the same time. - [#​17857](withastro/astro#17857) [`2637ed1`](withastro/astro@2637ed1) Thanks [@​Princesseuh](https://github.com/Princesseuh)! - Improves rendering performance - [#​17943](withastro/astro#17943) [`2fc7ce9`](withastro/astro@2fc7ce9) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes a WebAssembly error when importing `astro:actions` in tests that run under `@cloudflare/vitest-pool-workers` - [#​18018](withastro/astro#18018) [`1b5a234`](withastro/astro@1b5a234) Thanks [@​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. - [#​17905](withastro/astro#17905) [`eaf70fa`](withastro/astro@eaf70fa) Thanks [@​SudoDevStudio](https://github.com/SudoDevStudio)! - Fixes custom dev toolbar apps losing their UI after client-side navigation with `<ClientRouter />`. - [#​18011](withastro/astro#18011) [`558b301`](withastro/astro@558b301) Thanks [@​astro-factory](https://github.com/apps/astro-factory)! - Fixes prerendered Cloudflare pages rendering as `[object Object]` when `nodejs_compat` is enabled in `wrangler.toml` - [#​17944](withastro/astro#17944) [`ba08e35`](withastro/astro@ba08e35) Thanks [@​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. - [#​17531](withastro/astro#17531) [`ae837db`](withastro/astro@ae837db) Thanks [@​danilloestrela](https://github.com/danilloestrela)! - Updates `svgo` to `4.0.2` to resolve a security advisory - [#​17953](withastro/astro#17953) [`dbbf10e`](withastro/astro@dbbf10e) Thanks [@​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. - [#​17955](withastro/astro#17955) [`4e8ad9a`](withastro/astro@4e8ad9a) Thanks [@​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. - [#​17960](withastro/astro#17960) [`9838049`](withastro/astro@9838049) Thanks [@​Chy-Zaber-Bin-Zahid](https://github.com/Chy-Zaber-Bin-Zahid)! - Improves the diagnostics of some Astro errors. - [#​17998](withastro/astro#17998) [`0e5478d`](withastro/astro@0e5478d) Thanks [@​astro-factory](https://github.com/apps/astro-factory)! - Fixes SVG `<style>` elements nested inside `<defs>` or other container elements not being hashed for CSP - [#​17994](withastro/astro#17994) [`80f9f1d`](withastro/astro@80f9f1d) Thanks [@​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 - [#​17889](withastro/astro#17889) [`8ae6b46`](withastro/astro@8ae6b46) Thanks [@​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. - [#​17980](withastro/astro#17980) [`cfccafa`](withastro/astro@cfccafa) Thanks [@​gameroman](https://github.com/gameroman)! - Improves JSDoc for fonts api - [#​17953](withastro/astro#17953) [`dbbf10e`](withastro/astro@dbbf10e) Thanks [@​astro-factory](https://github.com/apps/astro-factory)! - Fixes CSS HMR for framework components rendered through content entries after `ClientRouter` navigation - [#​17970](withastro/astro#17970) [`0b4dc3a`](withastro/astro@0b4dc3a) Thanks [@​matthewp](https://github.com/matthewp)! - Improves serialization of transition animation values in generated CSS - [#​17999](withastro/astro#17999) [`30ef3cb`](withastro/astro@30ef3cb) Thanks [@​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'`) - [#​18002](withastro/astro#18002) [`312ab49`](withastro/astro@312ab49) Thanks [@​shoutoutuoadi325](https://github.com/shoutoutuoadi325)! - Fixes redirect targets being corrupted when a dynamic route parameter value contains `$` replacement patterns like `$&` - [#​17937](withastro/astro#17937) [`e294953`](withastro/astro@e294953) Thanks [@​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. - [#​17945](withastro/astro#17945) [`750b4db`](withastro/astro@750b4db) Thanks [@​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-->
Changes
Revised after review (thanks @ematipico). Two changes remain:
RedirectWithNoLocation: this entry only had atitle; adds amessagethat says what happened and how to fix it (Astro.redirect()or aLocationheader).RewriteWithBodyUsed: adds a hint that names the mechanism, read the body fromAstro.request.clone()so the original request can still be rewritten, without assuming a body format.No
nameortitlewas changed. Changeset:'astro': patch.Testing
Text-only change, so no new tests. Locally:
pnpm -C packages/astro build, thenpackages/astro/test/units/errors/passes, and the CLI error formatter renders the new text. Biome and ESLint are clean on the changed file.Docs
The error reference at docs.astro.build is generated from
errors-data.ts, so the new text will appear there on the next docs build; no docs PR needed.