@@ -118,11 +118,17 @@ export function initWrapperState(element: Element, props: Object) {
118
118
}
119
119
120
120
var defaultValue = props . defaultValue == null ? '' : props . defaultValue ;
121
+ var initialValue = props . value != null ? props . value : defaultValue ;
121
122
var node = ( ( element : any ) : InputWithWrapperState ) ;
123
+
124
+ if ( ! shouldSetAttribute ( 'value' , initialValue ) ) {
125
+ initialValue = '' ;
126
+ }
127
+
122
128
node . _wrapperState = {
123
129
initialChecked :
124
130
props . checked != null ? props . checked : props . defaultChecked ,
125
- initialValue : props . value != null ? props . value : defaultValue ,
131
+ initialValue : initialValue ,
126
132
controlled : isControlled ( props ) ,
127
133
} ;
128
134
}
@@ -200,11 +206,11 @@ export function updateWrapper(element: Element, props: Object) {
200
206
} else if ( node . value !== '' + value ) {
201
207
node . value = '' + value ;
202
208
}
209
+ }
210
+
211
+ if ( props . hasOwnProperty ( 'value' ) ) {
203
212
synchronizeDefaultValue ( node , props . type , value ) ;
204
- } else if (
205
- props . hasOwnProperty ( 'value' ) ||
206
- props . hasOwnProperty ( 'defaultValue' )
207
- ) {
213
+ } else if ( props . hasOwnProperty ( 'defaultValue' ) ) {
208
214
synchronizeDefaultValue ( node , props . type , defaultValue ) ;
209
215
}
210
216
@@ -215,21 +221,18 @@ export function updateWrapper(element: Element, props: Object) {
215
221
216
222
export function postMountWrapper ( element : Element , props : Object ) {
217
223
var node = ( ( element : any ) : InputWithWrapperState ) ;
218
- var initialValue = node . _wrapperState . initialValue ;
219
224
220
- if ( props . value != null || props . defaultValue != null ) {
225
+ if ( props . hasOwnProperty ( ' value' ) || props . hasOwnProperty ( ' defaultValue' ) ) {
221
226
// Do not assign value if it is already set. This prevents user text input
222
227
// from being lost during SSR hydration.
223
- if ( node . value === '' && shouldSetAttribute ( 'value' , initialValue ) ) {
224
- node . value = '' + initialValue ;
228
+ if ( node . value === '' ) {
229
+ node . value = '' + node . _wrapperState . initialValue ;
225
230
}
226
231
227
232
// value must be assigned before defaultValue. This fixes an issue where the
228
233
// visually displayed value of date inputs disappears on mobile Safari and Chrome:
229
234
// https://github.com/facebook/react/issues/7233
230
- if ( shouldSetAttribute ( 'value' , initialValue ) ) {
231
- node . defaultValue = '' + initialValue ;
232
- }
235
+ node . defaultValue = '' + node . _wrapperState . initialValue ;
233
236
}
234
237
235
238
// Normally, we'd just do `node.checked = node.checked` upon initial mount, less this bug
@@ -320,10 +323,10 @@ export function synchronizeDefaultValue(
320
323
type !== 'number' ||
321
324
node . ownerDocument . activeElement !== node
322
325
) {
323
- var nextValue =
324
- '' + ( value == null ? node . _wrapperState . initialValue : value ) ;
325
- if ( nextValue !== node . defaultValue ) {
326
- node . defaultValue = nextValue ;
326
+ if ( value == null ) {
327
+ node . defaultValue = '' + node . _wrapperState . initialValue ;
328
+ } else if ( node . defaultValue !== '' + value ) {
329
+ node . defaultValue = '' + value ;
327
330
}
328
331
}
329
332
}
0 commit comments