Skip to content

[React 19] Submitting a <form> with an action will clear the input values #31649

@debel27

Description

@debel27

Summary

I think a regression was introduced during the development of React 19 Canary.

Steps to reproduce

Render the following form and type something into the "query" input.

<form action={() => {}}>
  <input name="query" />
  <button type="submit">Search</button>
</form>
  • up until 19.0.0-canary-4c12339ce-20240408, submitting the form will preserve the input value
  • from 19.0.0-canary-adb717393-20240411 onwards, submitting the form will clear the input value

https://codesandbox.io/p/sandbox/elastic-merkle-yykcrc

Why I think this is a bug

Clearing inputs can be problematic if we keep displaying the form after submission.

A classical example is the display of validation errors after a rejected submit (by using the information returned by useActionState, for instance). If the inputs are cleared after submit, the errors would show up under empty inputs, which is not very helpful. Also, the user would have to fill in the complete form again, instead of simply fixing invalid values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions