Skip to content

React 19 Actions + RAC Form aren't working properly due to automatic form reset #6830

Open
1 of 2 issues completed
@pawelblaszczyk5

Description

@pawelblaszczyk5

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:

  1. This form reset sets the value to defaultValue that was initially passed, not to the current defaultValue one:

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.

  1. Errors passed from action state to validationErrors prop on Form aren't properly used because the Form validation state is discarded with form reset event. I'm not 100% sure but I feel like it's here in code:

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:

  1. 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 defaultValue being updated. Obviously this misses RAC a11y stuff and all the goodies
  2. Using actions with RAC, you can observe that the error isn't properly being displayed after submission and the value is being reset despite defaultValue being updated
  3. 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

No one assigned

    Type

    No type

    Projects

    Status

    🔬 To Investigate / Verify

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions