Skip to content

Commit 0cfc69d

Browse files
apatel369ematipico
andauthoredOct 28, 2024··
fix(actions): pass actionAPIContext to action handler instead of APIContext (#12301)
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
1 parent ecc4402 commit 0cfc69d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed
 

‎.changeset/shy-eggs-grin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes an issue with action handler context by passing the correct context (`ActionAPIContext`).

‎packages/astro/src/actions/runtime/middleware.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ async function handlePost({
9999
if (contentType && hasContentType(contentType, formContentTypes)) {
100100
formData = await request.clone().formData();
101101
}
102-
const action = baseAction.bind(context);
102+
const { getActionResult, callAction, props, redirect, ...actionAPIContext } = context;
103+
const action = baseAction.bind(actionAPIContext);
103104
const actionResult = await action(formData);
104105

105106
if (context.url.searchParams.get(ACTION_QUERY_PARAMS.actionRedirect) === 'false') {

‎packages/astro/src/actions/runtime/route.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export const POST: APIRoute = async (context) => {
2727
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415
2828
return new Response(null, { status: 415 });
2929
}
30-
const action = baseAction.bind(context);
30+
const { getActionResult, callAction, props, redirect, ...actionAPIContext } = context;
31+
const action = baseAction.bind(actionAPIContext);
3132
const result = await action(args);
3233
const serialized = serializeActionResult(result);
3334

0 commit comments

Comments
 (0)
Please sign in to comment.