Skip to content

Commit 7306a26

Browse files
[v6] remove context.rewrite in actions (#12477)
Co-authored-by: Sarah Rainsberger <[email protected]>
1 parent e3e6ab4 commit 7306a26

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/content/docs/en/guides/actions.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ Actions are accessible as public endpoints based on the name of the action. For
656656

657657
To authorize action requests, add an authentication check to your action handler. You may want to use [an authentication library](/en/guides/authentication/) to handle session management and user information.
658658

659-
Actions expose the full `APIContext` object to access properties passed from middleware using `context.locals`. When a user is not authorized, you can raise an `ActionError` with the `UNAUTHORIZED` code:
659+
Actions expose the `ActionAPIContext` object, a subset of `APIContext`, to access properties passed from middleware using `context.locals`. When a user is not authorized, you can raise an `ActionError` with the `UNAUTHORIZED` code:
660660

661661
```ts title="src/actions/index.ts" {6-8}
662662
import { defineAction, ActionError } from 'astro:actions';

src/content/docs/en/guides/upgrade-to/v6.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,38 @@ prefetch('/about');
371371

372372
<ReadMore>Learn more about [prefetching](/en/guides/prefetch/).</ReadMore>
373373

374+
### Removed: `rewrite()` from Actions context
375+
376+
<SourcePR number="14477" title="feat!: remove rewrite from action context"/>
377+
378+
In Astro 5.5.6, the `ActionAPIContext.rewrite` method was deprecated because custom endpoints should be used instead of rewrites.
379+
380+
Astro 6.0 removes the `rewrite()` method from `ActionAPIContext` entirely and it may no longer be used.
381+
382+
#### What should I do?
383+
384+
Review your Actions handlers and remove any call to `rewrite()`:
385+
386+
387+
```ts title="src/actions/index.ts" del={10}
388+
import { defineAction } from 'astro:actions';
389+
import { z } from 'astro:schema';
390+
391+
export const server = {
392+
getGreeting: defineAction({
393+
input: z.object({
394+
// ...
395+
}),
396+
handler: async (input, context) => {
397+
context.rewrite('/')
398+
// ...
399+
}
400+
})
401+
}
402+
```
403+
404+
<ReadMore>Learn more about [rewrites](/en/guides/routing/#rewrites).</ReadMore>
405+
374406
### Experimental Flags
375407

376408
The following experimental flags have been removed in Astro v6.0 and these features are available for use:

src/content/docs/en/reference/modules/astro-actions.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const server = {
6161

6262
`defineAction()` requires a `handler()` function containing the server logic to run when the action is called. Data returned from the handler is automatically serialized and sent to the caller.
6363

64-
The `handler()` is called with user input as its first argument. If an [`input`](#input-validator) validator is set, the user input will be validated before being passed to the handler. The second argument is a `context` object containing most of Astro’s [standard endpoint context](/en/reference/api-reference/), excluding `getActionResult()`, `callAction()`, and `redirect()`.
64+
The `handler()` is called with user input as its first argument. If an [`input`](#input-validator) validator is set, the user input will be validated before being passed to the handler. The second argument is a `context` object containing most of Astro’s [standard endpoint context](/en/reference/api-reference/), excluding `getActionResult()`, `callAction()`, `redirect()` and `rewrite()`.
6565

6666
Return values are parsed using the [devalue library](https://github.com/Rich-Harris/devalue). This supports JSON values and instances of `Date()`, `Map()`, `Set()`, and `URL()`.
6767

0 commit comments

Comments
 (0)