File tree 2 files changed +27
-1
lines changed
src/renderers/dom/client/wrappers
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -213,7 +213,11 @@ var ReactDOMInput = {
213
213
}
214
214
} else {
215
215
if ( props . value == null && props . defaultValue != null ) {
216
- node . defaultValue = '' + props . defaultValue ;
216
+ // Assigning defaultValue causes side-effects on value, which can cause
217
+ // unexpected value changes and selections skipping. A quick check avoids this
218
+ if ( node . defaultValue !== '' + props . defaultValue ) {
219
+ node . defaultValue = '' + props . defaultValue ;
220
+ }
217
221
}
218
222
if ( props . checked == null && props . defaultChecked != null ) {
219
223
node . defaultChecked = ! ! props . defaultChecked ;
Original file line number Diff line number Diff line change @@ -51,6 +51,28 @@ describe('ReactDOMInput', () => {
51
51
expect ( node . value ) . toBe ( '0' ) ;
52
52
} ) ;
53
53
54
+ it ( 'only assigns defaultValue if it changes' , ( ) => {
55
+ class Test extends React . Component {
56
+ render ( ) {
57
+ return ( < input defaultValue = "0" /> ) ;
58
+ }
59
+ }
60
+
61
+ var component = ReactTestUtils . renderIntoDocument ( < Test /> ) ;
62
+ var node = ReactDOM . findDOMNode ( component ) ;
63
+
64
+ Object . defineProperty ( node , 'defaultValue' , {
65
+ get ( ) {
66
+ return '0' ;
67
+ } ,
68
+ set ( value ) {
69
+ throw new Error ( `defaultValue was assigned ${ value } , but it did not change!` ) ;
70
+ } ,
71
+ } ) ;
72
+
73
+ component . forceUpdate ( ) ;
74
+ } ) ;
75
+
54
76
it ( 'should display "true" for `defaultValue` of `true`' , ( ) => {
55
77
var stub = < input type = "text" defaultValue = { true } /> ;
56
78
stub = ReactTestUtils . renderIntoDocument ( stub ) ;
You can’t perform that action at this time.
0 commit comments