Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dirty-dryers-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a bug that caused a session error to be logged when using actions without sessions
22 changes: 15 additions & 7 deletions packages/astro/src/actions/runtime/virtual/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down