Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: useFormState formAction becomes null in strict mode #28556

Closed
akmtagline opened this issue Mar 14, 2024 · 1 comment · Fixed by #28557
Closed

Bug: useFormState formAction becomes null in strict mode #28556

akmtagline opened this issue Mar 14, 2024 · 1 comment · Fixed by #28557

Comments

@akmtagline
Copy link

The form action returned from the hook useFormState becomes null when using React strict mode. It causes the page to reload on the submission of the form and the action does not work. I know that the React strict mode performs some actions twice intentionally to find unexpected behavior in the development. But, it would be better if we could use it without disabling the Strict mode.

React version: 0.0.0-experimental-bb0944fe5-20240313

Steps To Reproduce

  1. Enable strict mode
  2. Submit the form that uses form action returned from useFormState

Link to code example:
https://codesandbox.io/p/sandbox/jolly-minsky-kmkspd
https://codesandbox.io/p/sandbox/damp-tree-yv2vzy

The current behavior

Form action becomes null causing the page to reload.

The expected behavior

Form action should be a function provided as the argument in the useFormState hook.

@akmtagline akmtagline added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Mar 14, 2024
@eps1lon
Copy link
Collaborator

eps1lon commented Mar 14, 2024

I simplified the repro to a single file since the use server; directive has no effect in CodeSandbox: https://codesandbox.io/p/sandbox/useformstate-strictmode-double-invoke-action-nulled-6ltttr

18.3.0-canary-bb0944fe5-20240313: bad
18.3.0-canary-b36ae8d7a-20231207: good
18.3.0-canary-971b62f47-20240129: good
18.3.0-canary-2e470a788-20240214: good
18.3.0-canary-01ab35a9a-20240228: good
18.3.0-canary-0066e0b68-20240306: good
18.3.0-canary-eb33bd747-20240312: good

Last good: 18.3.0-canary-eb33bd747-20240312
First bad: 18.3.0-canary-bb0944fe5-20240313

New changes in 18.3.0-canary-bb0944fe5-20240313: eb33bd7...bb0944f

Looks like #28514 broke this.

@eps1lon eps1lon added Type: Bug React 19 and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants