Skip to content

Commit c2dfe51

Browse files
sebmarkbagekoto
authored andcommitted
Let value override defaultValue if both are specified (facebook#21369)
There's a DEV warning for this case but we still test for the production behavior.
1 parent 595b7b6 commit c2dfe51

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

packages/react-dom/src/server/ReactDOMServerFormatConfig.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,11 @@ function pushInput(
810810

811811
target.push(startChunkForTag('input'));
812812

813+
let value = null;
814+
let defaultValue = null;
815+
let checked = null;
816+
let defaultChecked = null;
817+
813818
for (const propKey in props) {
814819
if (hasOwnProperty.call(props, propKey)) {
815820
const propValue = props[propKey];
@@ -827,21 +832,35 @@ function pushInput(
827832
);
828833
// eslint-disable-next-line-no-fallthrough
829834
case 'defaultChecked':
830-
// Previously "checked" would win but now it's enumeration order dependent.
831-
// There's a warning in either case.
832-
pushAttribute(target, responseState, 'checked', propValue);
835+
defaultChecked = propValue;
833836
break;
834837
case 'defaultValue':
835-
// Previously "value" would win but now it's enumeration order dependent.
836-
// There's a warning in either case.
837-
pushAttribute(target, responseState, 'value', propValue);
838+
defaultValue = propValue;
839+
break;
840+
case 'checked':
841+
checked = propValue;
842+
break;
843+
case 'value':
844+
value = propValue;
838845
break;
839846
default:
840847
pushAttribute(target, responseState, propKey, propValue);
841848
break;
842849
}
843850
}
844851
}
852+
853+
if (checked !== null) {
854+
pushAttribute(target, responseState, 'checked', checked);
855+
} else if (defaultChecked !== null) {
856+
pushAttribute(target, responseState, 'checked', defaultChecked);
857+
}
858+
if (value !== null) {
859+
pushAttribute(target, responseState, 'value', value);
860+
} else if (defaultValue !== null) {
861+
pushAttribute(target, responseState, 'value', defaultValue);
862+
}
863+
845864
if (assignID !== null) {
846865
pushID(target, responseState, assignID, props.id);
847866
}
@@ -877,6 +896,7 @@ function pushStartTextArea(
877896
target.push(startChunkForTag('textarea'));
878897

879898
let value = null;
899+
let defaultValue = null;
880900
let children = null;
881901
for (const propKey in props) {
882902
if (hasOwnProperty.call(props, propKey)) {
@@ -889,11 +909,11 @@ function pushStartTextArea(
889909
children = propValue;
890910
break;
891911
case 'value':
892-
case 'defaultValue':
893-
// Previously "checked" would win but now it's enumeration order dependent.
894-
// There's a warning in either case.
895912
value = propValue;
896913
break;
914+
case 'defaultValue':
915+
defaultValue = propValue;
916+
break;
897917
case 'dangerouslySetInnerHTML':
898918
invariant(
899919
false,
@@ -906,6 +926,10 @@ function pushStartTextArea(
906926
}
907927
}
908928
}
929+
if (value === null && defaultValue !== null) {
930+
value = defaultValue;
931+
}
932+
909933
if (assignID !== null) {
910934
pushID(target, responseState, assignID, props.id);
911935
}

0 commit comments

Comments
 (0)