React 19 Actions + RAC Form
aren't working properly due to automatic form reset
#6830
Labels
Form
aren't working properly due to automatic form reset
#6830
Provide a general summary of the issue here
React 19 actions has behavior (that was added in canary cycle after
Form
component in RAC and documentation around it) that it automatically resets form after submission to mimic default browser behavior - PR Link.I spotted two things that it's breaking while using RAC
Form
:defaultValue
that was initially passed, not to the currentdefaultValue
one:react-spectrum/packages/@react-aria/utils/src/useFormReset.ts
Lines 22 to 25 in 455cbf4
This isn't working correctly with the recommended pattern by React that defaultValue represent canonical state from the server.
validationErrors
prop onForm
aren't properly used because theForm
validation state is discarded with form reset event. I'm not 100% sure but I feel like it's here in code:react-spectrum/packages/@react-aria/form/src/useFormValidation.ts
Lines 46 to 48 in 455cbf4
This breaks the pattern where action returns some additional errors that can be created only from the server. This is also the pattern used in the RAC docs.
🤔 Expected Behavior?
React 19 patterns where you use actions to drive both canonical form state and form errors works correctly. You use
defaultValue
with theformData
to prevent the values from being reset and you can pass errors toForm
component and they're properly displayed.😯 Current Behavior
React 19 automatic reset behavior breaks both form state and errors state
💁 Possible Solution
I'm not sure here
🔦 Context
I'm building an SPA app with React 19 RC version and noticed that actions doesn't really work properly with RAC form handling
🖥️ Steps to Reproduce
I created a reproduction:
https://stackblitz.com/edit/vitejs-vite-edgrdn?file=src/App.tsx,package.json
There're three forms rendered:
defaultValue
being updated. Obviously this misses RAC a11y stuff and all the goodiesdefaultValue
being updatedVersion
RAC 1.3.1
What browsers are you seeing the problem on?
Firefox, Chrome, Safari, Microsoft Edge
If other, please specify.
No response
What operating system are you using?
MacOS Sonoma 14.5, Windows 11
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response
The text was updated successfully, but these errors were encountered: