Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 90ed488

Browse files
committedNov 27, 2017
Improve clarity of value checks in ReactDOMInput.postMountWrapper
1 parent fde83b2 commit 90ed488

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed
 

‎packages/react-dom/src/client/ReactDOMFiberInput.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,19 @@ export function updateWrapper(element: Element, props: Object) {
215215

216216
export function postMountWrapper(element: Element, props: Object) {
217217
var node = ((element: any): InputWithWrapperState);
218-
var hasUserInput = node.value !== '';
219-
var value = node._wrapperState.initialValue;
218+
var initialValue = node._wrapperState.initialValue;
220219

221-
if (value !== '' || props.hasOwnProperty('value')) {
220+
if (props.hasOwnProperty('value') || props.hasOwnProperty('defaultValue')) {
222221
// Do not assign value if it is already set. This prevents user text input
223222
// from being lost during SSR hydration.
224-
if (!hasUserInput) {
225-
node.value = value;
223+
if (node.value === '') {
224+
node.value = initialValue;
226225
}
227226

228227
// value must be assigned before defaultValue. This fixes an issue where the
229228
// visually displayed value of date inputs disappears on mobile Safari and Chrome:
230229
// https://github.com/facebook/react/issues/7233
231-
node.defaultValue = value;
230+
node.defaultValue = initialValue;
232231
}
233232

234233
// Normally, we'd just do `node.checked = node.checked` upon initial mount, less this bug

0 commit comments

Comments
 (0)
Please sign in to comment.