-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
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:
- This form reset sets the value to
defaultValuethat was initially passed, not to the currentdefaultValueone:
react-spectrum/packages/@react-aria/utils/src/useFormReset.ts
Lines 22 to 25 in 455cbf4
| let resetValue = useRef(initialValue); | |
| let handleReset = useEffectEvent(() => { | |
| if (onReset) { | |
| onReset(resetValue.current); |
This isn't working correctly with the recommended pattern by React that defaultValue represent canonical state from the server.
- Errors passed from action state to
validationErrorsprop onFormaren't properly used because theFormvalidation 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
| let onReset = useEffectEvent(() => { | |
| state.resetValidation(); | |
| }); |
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 the formData to prevent the values from being reset and you can pass errors to Form 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:
- Using actions without RAC, example of how React actions should be used. The error is properly displayed after submission, the value is being keep because of the
defaultValuebeing updated. Obviously this misses RAC a11y stuff and all the goodies - Using actions with RAC, you can observe that the error isn't properly being displayed after submission and the value is being reset despite
defaultValuebeing updated - RAC without actions, using plain state, just to confirm that it works in React 19 and how +- it's supposed to behave
Version
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
Sub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
Status