@samitouri / QOS-React / commits / 2182563dc4

Let value override defaultValue if both are specified (#21369)

There's a DEV warning for this case but we still test for the production behavior.

Sebastian Markbåge committed Apr 27, 2021 at 16:18 UTC 2182563dc400b51fccea034dfcebe2aff9ee979e
1 file changed +33 -9
packages/react-dom/src/server/ReactDOMServerFormatConfig.js
+33 -9
@@ -810,6 +810,11 @@ function pushInput(
810
811 target.push(startChunkForTag('input'));
812
813 + let value = null;
814 + let defaultValue = null;
815 + let checked = null;
816 + let defaultChecked = null;
817 +
818 for (const propKey in props) {
819 if (hasOwnProperty.call(props, propKey)) {
820 const propValue = props[propKey];
@@ -827,14 +832,16 @@ function pushInput(
832 );
833 // eslint-disable-next-line-no-fallthrough
834 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;
836 break;
837 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;
845 break;
846 default:
847 pushAttribute(target, responseState, propKey, propValue);
@@ -842,6 +849,18 @@ function pushInput(
849 }
850 }
851 }
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 +
864 if (assignID !== null) {
865 pushID(target, responseState, assignID, props.id);
866 }
@@ -877,6 +896,7 @@ function pushStartTextArea(
896 target.push(startChunkForTag('textarea'));
897
898 let value = null;
899 + let defaultValue = null;
900 let children = null;
901 for (const propKey in props) {
902 if (hasOwnProperty.call(props, propKey)) {
@@ -889,11 +909,11 @@ function pushStartTextArea(
909 children = propValue;
910 break;
911 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.
912 value = propValue;
913 break;
914 + case 'defaultValue':
915 + defaultValue = propValue;
916 + break;
917 case 'dangerouslySetInnerHTML':
918 invariant(
919 false,
@@ -906,6 +926,10 @@ function pushStartTextArea(
926 }
927 }
928 }
929 + if (value === null && defaultValue !== null) {
930 + value = defaultValue;
931 + }
932 +
933 if (assignID !== null) {
934 pushID(target, responseState, assignID, props.id);
935 }