-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Warning when changing the type and value of an input field #6441
Comments
Looks like we're applying the prop changes in a bad order. The logic to get this right is solvable in general (for known types), but could be complex to get perfect if we want to minimize DOM operations. |
I'm surprised that this particular case is problematic because this code should ensure that we always set
Not sure why that isn't working as designed. It's not totally clear to me whether setting type first always solves cases like these or setting type first would simply cause the same warning when switching the other way. (See also #2242, which is something we may want to have happen but may be difficult to implement cleanly in the current system. It was easier when we had full composite wrappers for these components but we no longer do. Creating a new element whenever the type changes could be surprising because it would mean that the ref to that component changes during the lifetime of the component which we never have elsewhere.) |
The easiest workaround here is to set a |
Could be caused by Object.assign V8 order bug? Or was this before 15? |
@gaearon this is still in the 15 release |
@gurinderhans Which browser? Also, can you provide a jsfiddle that demonstrates the issue? |
@jimfb Here you go. |
Following the chrome debugger I found this: PS: Of Course, removing the call to You could check for type change, and not set value, or update type and then set value inside |
Here is a simpler case reproducing the issue: https://jsfiddle.net/97gr5e65/1/ It seems to only happen if changing from |
This was an interesting bug to check out, so I did some poking around. My initial thought was just to assign https://github.com/facebook/react/compare/master...nhunzaker:nh-input-change-fix?expand=1 It eliminates the bug, but it's too simple. It feels shallow. What do you think? |
Can we move the |
Yes. I was also able to get test coverage on this. The value is nullified by the DOM when the type changes such that the the value is no longer valid, or if a new value is assigned that is not valid. Unrelated, it's pretty cool that JSDOM picks this up. Done in #7333 |
Still happens with version |
In my render method I have something like
If I first render this input as a number, (e.g.
dynamicTypeValue = 'number'; dynamicValue = 5
) but then change the input to a string: (dynamicTypeValue = 'string'; dynamicValue = '01/01/2016'
) I get a warningthat the new value is not a valid number:
Is this expected behavior?
The text was updated successfully, but these errors were encountered: