You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[React 19] Controlled <select> component is subject to automatic form reset #30580
Reacted by Alexander Bergström, Meryovi De Dios, MiroslavPetrik, Joe Maffei, Sekti, Marco Muser, Zeeshaan Lakdawala, gslarsen, Mitchell De Nardis, Ben Hancock and 34 more
Since useActionState passes the previous state and returns the updated state, we can reset the input and select values accordingly.
Here's an updated version of the code that properly handles resetting both the input and select elements:
"use client";import{useActionState,useState}from"react";// This function handles the form submissionfunctionadd(previousState,formData){// Process the formData and return the new stateconstnewState=Date.now();// Reset the input and select valuesformData.reset();returnnewState;}exportdefaultfunctionPage(){// useActionState hook manages the form state and actionconst[state,formAction]=useActionState(add,0);// Local state for input and select valuesconst[name,setName]=useState("");const[type,setType]=useState("2");return(<formaction={(e)=>{formAction(e);// Call the form actionsetName("");// Reset the input valuesetType("2");// Reset the select value}}><p>{state}</p><p><inputtype="text"value={name}onChange={(e)=>setName(e.target.value)}/></p><p><selectname="gender"value={type}onChange={(e)=>setType(e.target.value)}><optionvalue="1">1</option><optionvalue="2">2</option><optionvalue="3">3</option></select></p><button>submit</button></form>);}
Explanation:
add function:
Receives previousState and formData as arguments.
Processes the form data and returns a new state.
Resets the form fields by calling formData.reset(), which is a built-in method to reset form values.
form action handler:
Calls formAction to handle the form submission.
Resets the local state for the input and select elements to their initial values ("" and "2" respectively).
By incorporating these changes, the form submission will reset both the input and select elements properly.
@ujshaikh The expected behaviour is that the select component should behave the same way as the input component, when I click on the submit button, the action executes and then my 2 components should keep their state values, currently the input component is as expected and the select is reset to its default value instead of the one I chose before I submitted.
changed the title [-][React 19] The controlled component also resets the <select> after the action[/-][+][React 19] Controlled `<select>` component is subject to automatic form reset[/+]on Aug 2, 2024
This is indeed a bug, thank you for reporting. Only uncontrolled components should be automatically reset when the action prop is used. The <select> here is controlled though and shouldn't change its value after the form is submitted.
Reacted by Bobby Sciacchitano, Felipe Vidal, Adrian Gąsiorek, Jeremy Stepanek, Robin A. Meade, Alexander Bergström, almusdev, gslarsen, Deep3niinfotech, saneruby and 14 more
Using onSubmit instead of the action attribute avoids this issue. The <select> value is preserved when using onSubmit.
not the point here. if you canceldefault on onSubmit, then the useAction state code don't trigger. This is about when that code triggers and you explicitly set the values, which are not honored later on, as they would if it was a regular serverAction without useActionState.
I've also run into this issue. I'm on a Mac - noticing that when I swipe away from the browser (3-finger swipe on trackpad) to another desktop, then back to the browser, the select box updates correctly. Has anyone else noticed similar behaviour?
So many nasty bugs with react action and useActionState...
I am transitioning to use plain old onSubmit which works reliable and recommend others to do the same. Such kind of tricky bugs are just not worth to fight when they are in the core and not fixed for years
I even consider to move to Solid because of bugs like this(also not sure if that path will not have its own bugs).
I love React with its pretty robust and stable releases over the years, and respect the team making it.
But seems like reliability is no longer a priority for the React project, and focus is more on quantity of features over quality
🙁
@valerii15298 Just don't use action and useActionState. As you can see, this is an issue we have been complaining about since 2024. Combine useState, startTransition and onSubmit, and not only will you not have to deal with the factually broken APIs you've mentioned, you'll even have a lot more leeway about how to control your form submissions.
This also affects Next.js (await cookies()).set() in a very confusing way (all values update except the <select> value) - I created a reproduction for that here:
Activity
ujshaikh commentedon Aug 2, 2024
@cjg1122
Can you please add actual and expected behavior?
Deba0099 commentedon Aug 2, 2024
Since
useActionStatepasses the previous state and returns the updated state, we can reset the input and select values accordingly.Here's an updated version of the code that properly handles resetting both the
inputandselectelements:Explanation:
addfunction:previousStateandformDataas arguments.formData.reset(), which is a built-in method to reset form values.formaction handler:formActionto handle the form submission.inputandselectelements to their initial values (""and"2"respectively).By incorporating these changes, the form submission will reset both the
inputandselectelements properly.ujshaikh commentedon Aug 2, 2024
I tried with above example and getting this error

I think it happed due to mismatching of args for useActionState
const [state, formAction] = useActionState(fn, initialState, permalink?);src: https://react.dev/reference/react/useActionState
https://codesandbox.io/p/sandbox/react-dev-forked-qvpx9c?file=%2Fsrc%2FPage.js
cjg1122 commentedon Aug 2, 2024
@ujshaikh The expected behaviour is that the select component should behave the same way as the input component, when I click on the submit button, the action executes and then my 2 components should keep their state values, currently the input component is as expected and the select is reset to its default value instead of the one I chose before I submitted.
I've uploaded a gif of the demo.~
cjg1122 commentedon Aug 2, 2024
@Deba0099 I tried to setState the local state after the action is submitted, but the select component is still reset to the default value.
[-][React 19] The controlled component also resets the <select> after the action[/-][+][React 19] Controlled `<select>` component is subject to automatic form reset[/+]eps1lon commentedon Aug 2, 2024
This is indeed a bug, thank you for reporting. Only uncontrolled components should be automatically reset when the
actionprop is used. The<select>here is controlled though and shouldn't change its value after the form is submitted.Screen.Recording.2024-08-02.at.13.45.45.mov
-- https://codesandbox.io/p/sandbox/stupefied-cohen-n578l6
ujshaikh commentedon Aug 2, 2024
@cjg1122
Tried to reproduce and applied reset
https://codesandbox.io/p/sandbox/react-dev-forked-qvpx9c
AmanVerma2202 commentedon Aug 4, 2024
@cjg1122
fix: reset both input and select fields to default state after form submission
check out code 1 here :https://codesandbox.io/p/sandbox/react-dev-forked-vfpgnn?file=%2Fsrc%2FPage.js%3A20%2C31
check out code 2 here : https://codesandbox.io/p/sandbox/react-controlled-select-subject-for-form-reset-forked-ng44jt
dberardi99 commentedon Oct 13, 2024
Is this bug still present? I could work on it in this case
AmanVerma2202 commentedon Oct 13, 2024
jeremy-step commentedon Nov 28, 2024
This issue is in fact still present. Including 19.0.0-rc.1, 19.0.0-beta-26f2496093-20240514 and 19.0.0-rc-7670501b-20241124
18 remaining items
issakujitsuk commentedon Jul 23, 2025
Using
onSubmitinstead of theactionattribute avoids this issue. The<select>value is preserved when usingonSubmit.gcb commentedon Jul 23, 2025
not the point here. if you canceldefault on onSubmit, then the useAction state code don't trigger. This is about when that code triggers and you explicitly set the values, which are not honored later on, as they would if it was a regular serverAction without useActionState.
karolskolasinski commentedon Aug 24, 2025
Please fix this bug. There is no workaround.
gcb commentedon Aug 25, 2025
the workaround is very simple. don't use this and keep on using the old pattern:
...but yeah, would be nice if the helper method here worked for more than the "Static Counter Tutorial" example.
edit: bonus, template for the server-action workaround:
olayway commentedon Nov 10, 2025
Please fix this :)
gcb commentedon Nov 16, 2025
better title would be "[react 19+]
useActionStatefails to maintain controlled values, in several cases, after form submission"qjstuart commentedon Nov 26, 2025
I've also run into this issue. I'm on a Mac - noticing that when I swipe away from the browser (3-finger swipe on trackpad) to another desktop, then back to the browser, the select box updates correctly. Has anyone else noticed similar behaviour?
albr74 commentedon Dec 18, 2025
I have the same problem
Add comprehensive test coverage for all controlled input types
Fix controlled select reset behavior after form action
karlhorky commentedon Jan 21, 2026
@eps1lon thanks for making the PR #35168 for this in Nov 2025, great to see an official PR fixing it 🚀 I'm watching that PR now 👀
<select>value on form reset #35168karlhorky commentedon Jan 21, 2026
Workarounds
For anyone waiting, some workarounds that you may want to try:
keyprop on the<select>or component containing ituseTransition()workaround further up in this issue: [React 19] Controlled <select> component is subject to automatic form reset #30580useEffectworkaround from the other issue: [React 19] allow opting out of automatic form reset when Form Actions are used #29034 (comment)valerii15298 commentedon Apr 29, 2026
So many nasty bugs with react
actionanduseActionState...I am transitioning to use plain old
onSubmitwhich works reliable and recommend others to do the same. Such kind of tricky bugs are just not worth to fight when they are in the core and not fixed for yearsI even consider to move to Solid because of bugs like this(also not sure if that path will not have its own bugs).
I love React with its pretty robust and stable releases over the years, and respect the team making it.
But seems like reliability is no longer a priority for the React project, and focus is more on quantity of features over quality
🙁
LutherTS commentedon Apr 29, 2026
@valerii15298 Just don't use
actionanduseActionState. As you can see, this is an issue we have been complaining about since 2024. CombineuseState,startTransitionandonSubmit, and not only will you not have to deal with the factually broken APIs you've mentioned, you'll even have a lot more leeway about how to control your form submissions.karlhorky commentedon Sep 30, 2026
This also affects Next.js
(await cookies()).set()in a very confusing way (all values update except the<select>value) - I created a reproduction for that here:Screen.Recording.2026-09-30.at.15.32.28.mov