0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

fix(actions): pass actionAPIContext to action handler instead of APIContext (#12301)

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
This commit is contained in:
Arpan Patel 2024-10-28 10:10:18 -04:00 committed by GitHub
parent ecc4402b3a
commit 0cfc69d499
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes an issue with action handler context by passing the correct context (`ActionAPIContext`).

View file

@ -99,7 +99,8 @@ async function handlePost({
if (contentType && hasContentType(contentType, formContentTypes)) {
formData = await request.clone().formData();
}
const action = baseAction.bind(context);
const { getActionResult, callAction, props, redirect, ...actionAPIContext } = context;
const action = baseAction.bind(actionAPIContext);
const actionResult = await action(formData);
if (context.url.searchParams.get(ACTION_QUERY_PARAMS.actionRedirect) === 'false') {

View file

@ -27,7 +27,8 @@ export const POST: APIRoute = async (context) => {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415
return new Response(null, { status: 415 });
}
const action = baseAction.bind(context);
const { getActionResult, callAction, props, redirect, ...actionAPIContext } = context;
const action = baseAction.bind(actionAPIContext);
const result = await action(args);
const serialized = serializeActionResult(result);