Skip to content

Commit

Permalink
fix(actions): pass actionAPIContext to action handler instead of APIC…
Browse files Browse the repository at this point in the history
…ontext (#12301)

Co-authored-by: Emanuele Stoppa <[email protected]>
  • Loading branch information
apatel369 and ematipico authored Oct 28, 2024
1 parent ecc4402 commit 0cfc69d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-eggs-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue with action handler context by passing the correct context (`ActionAPIContext`).
3 changes: 2 additions & 1 deletion packages/astro/src/actions/runtime/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/actions/runtime/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 0cfc69d

Please sign in to comment.