-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Controlled <select> doesn't update in Firefox when also setting state in another event #12584
Comments
Thanks for the report and repro @benclive! Looks like a bug to me, we'll try to investigate it soon. If you'd like to try and find the root cause and send in a fix we'd greatly appreciate that too 🙂 |
I believe that the following issue occurs because onMouseDown Event |
@faefelipe This is a workaround rather than a solution. In your example, because you have the following line in 'handleMouseDown': |
Was just having a little poke at this. I believe @skiritsis is on the right track. There are two MouseDown events getting fired. First, a MouseDown fires when the I'd argue that this is not a bug. Firefox is giving you a more nuanced view of the state changes in the page than Chrome does. If you wanted to leverage this additional information, you could change the code to this:
However, this will result in the wrong thing being written to the state when "Submit" is clicked because, as @faefelipe points out, you're attaching the onMouseDown to the I really don't think anything within React needs to change for this error report. It's application specific behaviour that is based on fairly nuanced browser-dependent behaviour. We could pin one vendor to the other and force them to behave the same way, but that is complexity that has a cost over time. |
I'm having this issue too with a select input. However, instead of attaching my |
Closing per #12584 (comment) — doesn't seem like React could make that choice for you. |
@jacksongabbard We do use We think that the component
|
Clicking on an option within <select> fires 2x mousedown events on <select> in Firefox, which reverts the selected element to default ("ANY"). See facebook/react#12584
Reporting a Bug
What is the current behavior?
When selecting a value in a React controlled select box in Firefox, the selection doesn't change. This occurs when a MouseDown handler also generates a state change.
It seems to occur when the MouseDown handler sets the state and re-renders the dropdown before the onChange event handler fires. The onChange is then triggered with the old select value because React provided the old state during the re-render.
CodePen (modified example from the Docs): https://codepen.io/anon/pen/zWyJqg?editors=0010
Steps to reproduce:
What is the expected behavior?
Select dropdown is updated and the value is available in React.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Tested on Firefox v59.0.2 (Development Edition and Normal) on OSX using React v16.3.1 and v16.1.1
Also encountered on Windows but I'm not sure of the exact versions.
Tested on Chrome and everything works as intended on OSX and Windows.
The text was updated successfully, but these errors were encountered: