facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
228.53k stars 46.77k forks source link

[React 19] `form.requestSubmit()` resets input value/defaultValue after transition #30532

Closed andrematulionis-nomad closed 2 months ago

andrematulionis-nomad commented 2 months ago

Summary

When form is submitted through form.requestSubmit() the input displays the older value instead of the current state.

https://github.com/user-attachments/assets/37bcbaaf-b680-43f0-95db-a57d276753a1

I tested using value and defaultValue props, and both leads to the same issue. When the form is submitted through <button type="submit"> it works fine, and form.submit() also has no problem, the issue is only using form.requestSubmit(). I suspect that this is an issue in react-dom reconciler. The state is correct in the log, but the actual <input> value is not. In the repro there is an useOptimistic but this happens without it too.

Repro: https://stackblitz.com/edit/vitejs-vite-i9sbuj?file=src%2FApp.tsx

Version:

"react": "^19.0.0-rc-941e1b4a-20240729",
"react-dom": "^19.0.0-rc-941e1b4a-20240729"

To make sure this wasn't reported, I tried searching for transition state reset, useActionState and requestSubmit, didn't find anything related.

eps1lon commented 2 months ago

This is intended behavior when using Form Actions to match the default HTML behavior which is also the behavior you'd get before hydration.

Closing as a duplicate of https://github.com/facebook/react/issues/29034