From 0cfc69d499815d4e1f1dc37cf32653195586087a Mon Sep 17 00:00:00 2001 From: Arpan Patel Date: Mon, 28 Oct 2024 10:10:18 -0400 Subject: [PATCH] fix(actions): pass actionAPIContext to action handler instead of APIContext (#12301) Co-authored-by: Emanuele Stoppa --- .changeset/shy-eggs-grin.md | 5 +++++ packages/astro/src/actions/runtime/middleware.ts | 3 ++- packages/astro/src/actions/runtime/route.ts | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/shy-eggs-grin.md diff --git a/.changeset/shy-eggs-grin.md b/.changeset/shy-eggs-grin.md new file mode 100644 index 000000000000..58a92c3c4bd8 --- /dev/null +++ b/.changeset/shy-eggs-grin.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an issue with action handler context by passing the correct context (`ActionAPIContext`). diff --git a/packages/astro/src/actions/runtime/middleware.ts b/packages/astro/src/actions/runtime/middleware.ts index 5107e10c2d0e..26966553149a 100644 --- a/packages/astro/src/actions/runtime/middleware.ts +++ b/packages/astro/src/actions/runtime/middleware.ts @@ -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') { diff --git a/packages/astro/src/actions/runtime/route.ts b/packages/astro/src/actions/runtime/route.ts index d10989614f42..103936d72005 100644 --- a/packages/astro/src/actions/runtime/route.ts +++ b/packages/astro/src/actions/runtime/route.ts @@ -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);