Skip to content

Commit e4f68fe

Browse files
committed
Revert toString change. Only assign unsynced values when not nully
1 parent fa10f5f commit e4f68fe

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

packages/react-dom/src/client/ReactDOMInput.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,17 @@ export function postMountWrapper(
252252
return;
253253
}
254254

255-
const initialValue = node._wrapperState.initialValue;
255+
const initialValue = toString(node._wrapperState.initialValue);
256256

257257
// Do not assign value if it is already set. This prevents user text input
258258
// from being lost during SSR hydration.
259259
if (!isHydrating) {
260260
if (disableInputAttributeSyncing) {
261+
const value = getToStringValue(props.value);
262+
261263
// When not syncing the value attribute, the value property points
262264
// directly to the React prop. Only assign it if it exists.
263-
if (props.hasOwnProperty('value')) {
264-
const value = getToStringValue(props.value);
265-
265+
if (value != null) {
266266
// Always assign on buttons so that it is possible to assign an
267267
// empty string to clear button text.
268268
//
@@ -283,22 +283,23 @@ export function postMountWrapper(
283283
// 2. The defaultValue React property when present
284284
// 3. An empty string
285285
if (initialValue !== node.value) {
286-
node.value = toString(initialValue);
286+
node.value = initialValue;
287287
}
288288
}
289289
}
290290

291291
if (disableInputAttributeSyncing) {
292292
// When not syncing the value attribute, assign the value attribute
293293
// directly from the defaultValue React property (when present)
294-
if (props.hasOwnProperty('defaultValue')) {
295-
node.defaultValue = toString(getToStringValue(props.defaultValue));
294+
const defaultValue = getToStringValue(props.defaultValue);
295+
if (defaultValue != null) {
296+
node.defaultValue = toString(defaultValue);
296297
}
297298
} else {
298299
// Otherwise, the value attribute is synchronized to the property,
299300
// so we assign defaultValue to the same thing as the value property
300301
// assignment step above.
301-
node.defaultValue = toString(initialValue);
302+
node.defaultValue = initialValue;
302303
}
303304
}
304305

packages/react-dom/src/client/ToStringValue.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export opaque type ToStringValue =
1818
// Flow does not allow string concatenation of most non-string types. To work
1919
// around this limitation, we use an opaque type that can only be obtained by
2020
// passing the value through getToStringValue first.
21-
export function toString(value: ?ToStringValue): string {
22-
return value == null ? '' : '' + (value: any);
21+
export function toString(value: ToStringValue): string {
22+
return '' + (value: any);
2323
}
2424

2525
export function getToStringValue(value: mixed): ToStringValue {

0 commit comments

Comments
 (0)