-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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 inputs do not synchronize value or checked attribute #10150
Conversation
d25f3a7
to
467e5b5
Compare
This commit is a follow up to prior work to resolve issues with number inputs in React. Inputs keep their value/checked attribute in sync with the value/checked property. This is a React behavior. Traditionally browser DOM manipulation does not rely on keeping the value/checked attribute in sync. It's also very problematic for number inputs. After discussion, it was decided to make a breaking change to no longer sync up the value/checked attribute with it's assoicated property. For this to work, I made the following changes: - The value, defaultValue, checked and defaultChecked properties are now maintained within the HTML property config. - This required adding a filter to strip out the value property on selects and textareas - The logic to defer assignment of the value attribute has been removed form ChangeEventPlugin - defaultValue and defaultChecked are aliased to `value` and `checked` so that uncontrolled input attribute assignment works as intended.
467e5b5
to
094ba20
Compare
Added a test plan. |
Is this breaking? Should it go into 15.x or 16? |
Definitely breaking. This should go in 16.x |
Are there consumers that depend on the attribute syncing? Why did we go that route originally, it was just for Form.reset? I'd think that if plugins/extensions relied on DOM syncing they would be wrong, right? |
Let's say we mention this as breaking change in the 16 blog post. What would the text be? (I'm trying to understand the full implications for consumers.) |
@jquense that's essentially the answer we got initially. It's not clear how many plugins/extensions depend on this behavior.
@gaearon I think it would need to touch on:
|
Yes, part of the reasoning was just attribute syncing, but it also got conflated with the
Yes, very much so IMHO. This is not "native behavior" that you can normally rely on. EDIT: AFAIK a lot of the background can be found in #5680 #6321 #6406, but they're long and hard to follow. |
For posterity: we decided to postpone this until 17. |
Closing for now, but let's revisit it for 17 (?! :)) |
Should we keep this open under a milestone if we think we want it? So we don't forget. |
Sure. I definitely want this. I'll do just that. Were you thinking a React 17 milestone, or something more specific to DOM stuff? |
We're tracking it in #11896 so I think we can close this PR as stale. We can always revive it later. |
This commit is a follow up to prior work to resolve issues with number inputs in React:
#7359 (comment)
More or less
A can of worms :). The discussion above concluded that React should not synchronize the value attribute/checked attribute for controlled inputs. This PR makes that change.
More info
Currently, inputs keep their value/checked attribute in sync with the value/checked property. This is a React behavior. Traditionally browser DOM manipulation does not rely on keeping the value/checked attribute in sync.
It's also very problematic for number inputs and (I believe) a few other obscure input bugs in IE/iOS Safari (this needs to be confirmed). After discussion, it was decided to make a breaking change to no longer sync up the value/checked attribute with it's associated property.
For this to work, I made the following changes:
value
,defaultValue
,checked
anddefaultChecked
properties are now maintained within the HTML property config.defaultValue
maps to thevalue
attribute, as doesdefaultChecked
tochecked
How to test this change
I've pushed a build of this version of React for our DOM fixtures here:
http://nh-no-input-value-attribute.surge.sh