@@ -118,11 +118,17 @@ export function initWrapperState(element: Element, props: Object) {
118118 }
119119
120120 var defaultValue = props . defaultValue == null ? '' : props . defaultValue ;
121+ var initialValue = props . value != null ? props . value : defaultValue ;
121122 var node = ( ( element : any ) : InputWithWrapperState ) ;
123+
124+ if ( ! shouldSetAttribute ( 'value' , initialValue ) ) {
125+ initialValue = '' ;
126+ }
127+
122128 node . _wrapperState = {
123129 initialChecked :
124130 props . checked != null ? props . checked : props . defaultChecked ,
125- initialValue : props . value != null ? props . value : defaultValue ,
131+ initialValue : initialValue ,
126132 controlled : isControlled ( props ) ,
127133 } ;
128134}
@@ -200,11 +206,11 @@ export function updateWrapper(element: Element, props: Object) {
200206 } else if ( node . value !== '' + value ) {
201207 node . value = '' + value ;
202208 }
209+ }
210+
211+ if ( props . hasOwnProperty ( 'value' ) ) {
203212 synchronizeDefaultValue ( node , props . type , value ) ;
204- } else if (
205- props . hasOwnProperty ( 'value' ) ||
206- props . hasOwnProperty ( 'defaultValue' )
207- ) {
213+ } else if ( props . hasOwnProperty ( 'defaultValue' ) ) {
208214 synchronizeDefaultValue ( node , props . type , defaultValue ) ;
209215 }
210216
@@ -215,21 +221,18 @@ export function updateWrapper(element: Element, props: Object) {
215221
216222export function postMountWrapper ( element : Element , props : Object ) {
217223 var node = ( ( element : any ) : InputWithWrapperState ) ;
218- var initialValue = node . _wrapperState . initialValue ;
219224
220- if ( props . value != null || props . defaultValue != null ) {
225+ if ( props . hasOwnProperty ( ' value' ) || props . hasOwnProperty ( ' defaultValue' ) ) {
221226 // Do not assign value if it is already set. This prevents user text input
222227 // 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 ;
225230 }
226231
227232 // value must be assigned before defaultValue. This fixes an issue where the
228233 // visually displayed value of date inputs disappears on mobile Safari and Chrome:
229234 // https://github.com/facebook/react/issues/7233
230- if ( shouldSetAttribute ( 'value' , initialValue ) ) {
231- node . defaultValue = '' + initialValue ;
232- }
235+ node . defaultValue = '' + node . _wrapperState . initialValue ;
233236 }
234237
235238 // Normally, we'd just do `node.checked = node.checked` upon initial mount, less this bug
@@ -320,10 +323,10 @@ export function synchronizeDefaultValue(
320323 type !== 'number' ||
321324 node . ownerDocument . activeElement !== node
322325 ) {
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 ;
327330 }
328331 }
329332}
0 commit comments