Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: select field value resets to the first option after form submission with useActionState #32362

Open
joshua-ots opened this issue Feb 12, 2025 · 6 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@joshua-ots
Copy link

joshua-ots commented Feb 12, 2025

When using a <select> field within a form that uses useActionState, the selected value resets to the first option after the form is submitted, even though the value should persist as defaultValue is set. This behavior occurs only with the <select> field; other form fields (e.g., text inputs) retain their values correctly after submission.

React version: 19

Steps To Reproduce

  1. Select 2 or 3 from the select field
  2. Press the button to submit the form

Link to code example: https://codesandbox.io/p/sandbox/sweet-swirles-l8f2j6?file=%2Fsrc%2FApp.js&from-embed=

The current behavior

After submission, the selected value resets to the first option (value='1').

The expected behavior

The selected value should persist.

@joshua-ots joshua-ots added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Feb 12, 2025
@apintorc
Copy link

Thanks for the input @joshua-ots, I discovered the same bug yesterday.
I have an edit form with many inputs and a select with several options. When I save this form, the inputs are updated the moment I click on the save button, but the select returns to the option before the save. Until the page is reloaded, the select does not show the correct option.
Please, I would like this bug to be fixed in React, as it is important that the select is updated at the time of saving.

@ConsoleTVs
Copy link

I can confirm this happens too. It's very annoying

@ICodeMyOwnLife
Copy link

I come here after spending the whole morning debugging why the select element in a form behaved so differently from other inputs. Tried to replace defaultValue on select with defaultCheck on options it still resets to the very first default value but not the latest one.

@LeonN534
Copy link

I asked about that bug 2 weeks ago on StackOverflow. Hope we find a solution 😄 .

@Ashish-619
Copy link

can this be only worked upon when the label Unconfirmed is removed?

@devpeakinnovations
Copy link

can this be only worked upon when the label Unconfirmed is removed?

Why, is it solved ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

7 participants