summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matt Kane <m@mk.gg> 2025-04-17 14:27:10 +0100
committerGravatar GitHub <noreply@github.com> 2025-04-17 14:27:10 +0100
commitffbe8f27a3e897971432eed1fde566db328b540d (patch)
treeb264f12a081ca6bf0e4c60c9f7bad15f9f16ce2f
parentce4e4121558b57142914f6ab203fec0859e75206 (diff)
downloadastro-ffbe8f27a3e897971432eed1fde566db328b540d.tar.gz
astro-ffbe8f27a3e897971432eed1fde566db328b540d.tar.zst
astro-ffbe8f27a3e897971432eed1fde566db328b540d.zip
fix: clone actionAPIContext preserving accessors (#13647)
-rw-r--r--.changeset/dirty-dryers-rush.md5
-rw-r--r--packages/astro/src/actions/runtime/virtual/server.ts22
2 files changed, 20 insertions, 7 deletions
diff --git a/.changeset/dirty-dryers-rush.md b/.changeset/dirty-dryers-rush.md
new file mode 100644
index 000000000..5950bde79
--- /dev/null
+++ b/.changeset/dirty-dryers-rush.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixes a bug that caused a session error to be logged when using actions without sessions
diff --git a/packages/astro/src/actions/runtime/virtual/server.ts b/packages/astro/src/actions/runtime/virtual/server.ts
index fe046701d..9fb560bef 100644
--- a/packages/astro/src/actions/runtime/virtual/server.ts
+++ b/packages/astro/src/actions/runtime/virtual/server.ts
@@ -300,13 +300,21 @@ export function getActionContext(context: APIContext): AstroActionContext {
}
throw e;
}
- const {
- props: _props,
- getActionResult: _getActionResult,
- callAction: _callAction,
- redirect: _redirect,
- ...actionAPIContext
- } = context;
+
+ const omitKeys = ['props', 'getActionResult', 'callAction', 'redirect'];
+
+ // Clones the context, preserving accessors and methods but omitting
+ // the properties that are not needed in the action handler.
+ const actionAPIContext = Object.create(
+ Object.getPrototypeOf(context),
+ Object.fromEntries(
+ Object.entries(Object.getOwnPropertyDescriptors(context))
+ .filter(([key]) =>
+ !omitKeys.includes(key)
+ )
+ )
+ );
+
Reflect.set(actionAPIContext, ACTION_API_CONTEXT_SYMBOL, true);
const handler = baseAction.bind(actionAPIContext satisfies ActionAPIContext);
return handler(input);