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);