summaryrefslogtreecommitdiff
path: root/packages/integrations/react
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/react')
-rw-r--r--packages/integrations/react/server.js7
-rw-r--r--packages/integrations/react/src/actions.ts5
2 files changed, 9 insertions, 3 deletions
diff --git a/packages/integrations/react/server.js b/packages/integrations/react/server.js
index 59134a699..6624a5610 100644
--- a/packages/integrations/react/server.js
+++ b/packages/integrations/react/server.js
@@ -131,6 +131,7 @@ async function getFormState({ result }) {
if (!actionResult) return undefined;
if (!isFormRequest(request.headers.get('content-type'))) return undefined;
+ const { searchParams } = new URL(request.url);
const formData = await request.clone().formData();
/**
* The key generated by React to identify each `useActionState()` call.
@@ -142,7 +143,11 @@ async function getFormState({ result }) {
* This matches the endpoint path.
* @example "/_actions/blog.like"
*/
- const actionName = formData.get('_astroAction')?.toString();
+ const actionName =
+ searchParams.get('_astroAction') ??
+ /* Legacy. TODO: remove for stable */ formData
+ .get('_astroAction')
+ ?.toString();
if (!actionKey || !actionName) return undefined;
diff --git a/packages/integrations/react/src/actions.ts b/packages/integrations/react/src/actions.ts
index 336d32220..bc45e28ee 100644
--- a/packages/integrations/react/src/actions.ts
+++ b/packages/integrations/react/src/actions.ts
@@ -25,8 +25,9 @@ export function experimental_withState<T>(action: FormFn<T>) {
callback.$$FORM_ACTION = action.$$FORM_ACTION;
// Called by React when form state is passed from the server.
// If the action names match, React returns this state from `useActionState()`.
- callback.$$IS_SIGNATURE_EQUAL = (actionName: string) => {
- return action.toString() === actionName;
+ callback.$$IS_SIGNATURE_EQUAL = (incomingActionName: string) => {
+ const actionName = new URLSearchParams(action.toString()).get('_astroAction');
+ return actionName === incomingActionName;
};
// React calls `.bind()` internally to pass the initial state value.