Skip to content

[React 19] Controlled checkboxes are reset by form submission and form.reset() #31695

Open

Description

@jeremy-deutsch

Summary

After a form is submitted with an action, if one of the form's fields is a checkbox or radio input controlled by its checked prop, that element is reset as if it were uncontrolled. The same happens when the reset() method is called on the form. (Expected behavior: those fields are not reset.)

import { useState } from "react"

export default function Page() {
  const [isChecked, setIsChecked] = useState(false);

  return (
    <form action={() => {
      console.log("hello world!");
    }}>
      <label>
        Some checkbox
        <input type="checkbox"
          checked={isChecked}
          onChange={(e) => {
            setIsChecked(e.target.checked);
          }}
        />
      </label>
      <button>Submit form</button>
    </form>
  );
}

Repro: https://codesandbox.io/p/sandbox/checkbox-reset-repro-sff3sr

Related: #30580, reactjs/react.dev#7340

Activity

  1. changed the title [-][React 19] Controlled checkboxes are reset automatically after form submission[/-] [+][React 19] Controlled checkboxes are reset by form submission and form.reset()[/+] on Dec 8, 2024
  2. ray-marr-ho commented on Dec 17, 2024

    @ray-marr-ho
  3. jeremy-deutsch commented on Feb 13, 2025

    @jeremy-deutsch
    Author

    @eps1lon is there any chance this issue (as well as #30580) could be given the normal bug tags ("status:unconfirmed" or "type:bug"), since it's a bug in stable React?

    I'm worried that this issue (as well as many others) isn't being triaged because the "React 19" issue tag was supposed to refer to the React 19 beta, even though it's mostly now being used to tag problems with stable React.

  4. github-actions commented on Jun 7, 2025

    @github-actions

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

  5. added
    Resolution: Stale
    on Jun 7, 2025
  6. jrenjilian commented on Jun 9, 2025

    @jrenjilian

    This is still an issue! We've needed to remember to manually reset controlled inputs when we use the form action system.

  7. removed
    Resolution: Stale
    on Jun 9, 2025
  8. AleTopp commented on Jun 30, 2025

    @AleTopp

    bump!

  9. ortin779 commented on Jul 3, 2025

    @ortin779
  10. kirilledelman commented on Jul 18, 2025

    @kirilledelman

    I've spent three days trying to understand what I was doing wrong, but turns out it was a React bug affecting very essential functionality, and it's over a year old!

  11. LeonBlade commented on Jul 23, 2025

    @LeonBlade

    Just ran into this issue. I did not expect this to be a bug with React, but here we are.

    My current workaround is to create my own checkbox component that uses a button and a hidden input. The boolean is just cast a string for the value of the hidden input. This does mean your form data will pass as a string, but that happens already normally with checkboxes as they get passed as "on" typically.

  12. kirilledelman commented on Jul 24, 2025

    @kirilledelman

    @LeonBlade My workaround was to simply add a completely redundant setRememberMe(rememberMe) at the end of the useEffect that interpreted formState after the server call returned. You don't have to send the actual value to the server. Apparently then it behaves like other controlled fields.

  13. LeonBlade commented on Jul 24, 2025

    @LeonBlade

    @kirilledelman It's a simple solution. I don't think I'll be using it though because it means having to add this logic to any form that might use checkboxes. That's why I opted to modify my component instead. Hopefully this can be addressed at some point.

  14. johnloven commented on Aug 14, 2025

    @johnloven

    Bumping this since it's still very much an issue, which is pretty insane.

  15. 16 remaining items

  16. removed
    Resolution: Stale
    on Jun 9, 2026
  17. karlhorky commented on Jun 10, 2026

    @karlhorky
    Contributor

    @eps1lon I guess this one should stay open and wait for your followup, right?

  18. github-actions commented on Sep 8, 2026

    @github-actions

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

  19. added
    Resolution: Stale
    on Sep 8, 2026
  20. mizdra commented on Sep 8, 2026

    @mizdra

    bump

  21. removed
    Resolution: Stale
    on Sep 8, 2026
  22. fey commented on Oct 30, 2026

    @fey

    Still reproduces on React 19.3.1 (react-dom 19.3.1, Chromium 156).

    A form with action={formAction} from useActionState, a controlled checkbox (checked={values.isAgreed}) and controlled radios (checked={values.delivery === "pickup"}). When the action returns validation errors, the checkbox and the radio in the DOM go back to their default state, while React state still holds isAgreed: true and delivery: "pickup". A submit button with disabled={!values.isAgreed} stays enabled next to an unchecked box. Controlled text inputs keep their values. A controlled <select> is reset the same way after a successful action (#30580).

    What we tried:

    Approach Checkbox and radio after the error
    controlled fields + action reset
    setting the same state again inside the action reset
    remounting the form with a new key on error kept
    onSubmit + startTransition(() => formAction(formData)) kept
    uncontrolled fields + defaultChecked from the action state kept

    We ran into this in a React course: students hit it in a form exercise and asked why the checkbox "drops". #37668 targets this issue and is waiting for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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