Skip to content

Commit fbf7069

Browse files
committed
Fix controlled radios, maybe for real this time (#27443)
Fixes #26876 for real? In 18.2.0 (last stable), we set .checked unconditionally: https://github.com/facebook/react/blob/v18.2.0/packages/react-dom/src/client/ReactDOMInput.js#L129-L135 This is important because if we are updating two radios' checkedness from (false, true) to (true, false), we need to make sure that input2.checked is explicitly set to false, even though setting `input1.checked = true` already unchecks input2. I think this fix is not complete because there is no guarantee that all the inputs rerender at the same time? Hence the TODO. But in practice they usually would and I _think_ this is comparable to what we had before. Also treating function and symbol as false like we used to and like we do on initial mount. DiffTrain build for [4f4c52a](4f4c52a)
1 parent 9d56820 commit fbf7069

14 files changed

Lines changed: 66 additions & 46 deletions

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
54baa7997c7b0bbd456460ead6e051655ea43790
1+
4f4c52a3c8f9c8a2d8133c654841fee257c37249

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-classic-591e80f2";
30+
var ReactVersion = "18.3.0-www-classic-ff54ec02";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,4 +615,4 @@ exports.useSyncExternalStore = function (
615615
exports.useTransition = function () {
616616
return ReactCurrentDispatcher.current.useTransition();
617617
};
618-
exports.version = "18.3.0-www-modern-96829b2e";
618+
exports.version = "18.3.0-www-modern-dc699db3";

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ exports.useSyncExternalStore = function (
626626
exports.useTransition = function () {
627627
return ReactCurrentDispatcher.current.useTransition();
628628
};
629-
exports.version = "18.3.0-www-modern-1a772a6d";
629+
exports.version = "18.3.0-www-modern-622fc29e";
630630

631631
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
632632
if (

compiled/facebook-www/ReactDOM-dev.classic.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,8 +3899,13 @@ function updateInput(
38993899
}
39003900
}
39013901

3902-
if (checked != null && node.checked !== !!checked) {
3903-
node.checked = checked;
3902+
if (checked != null) {
3903+
// Important to set this even if it's not a change in order to update input
3904+
// value tracking with radio buttons
3905+
// TODO: Should really update input value tracking for the whole radio
3906+
// button group in an effect or something (similar to #27024)
3907+
node.checked =
3908+
checked && typeof checked !== "function" && typeof checked !== "symbol";
39043909
}
39053910

39063911
if (
@@ -33972,7 +33977,7 @@ function createFiberRoot(
3397233977
return root;
3397333978
}
3397433979

33975-
var ReactVersion = "18.3.0-www-classic-707e543f";
33980+
var ReactVersion = "18.3.0-www-classic-9c42e3d4";
3397633981

3397733982
function createPortal$1(
3397833983
children,

compiled/facebook-www/ReactDOM-dev.modern.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,8 +3741,13 @@ function updateInput(
37413741
}
37423742
}
37433743

3744-
if (checked != null && node.checked !== !!checked) {
3745-
node.checked = checked;
3744+
if (checked != null) {
3745+
// Important to set this even if it's not a change in order to update input
3746+
// value tracking with radio buttons
3747+
// TODO: Should really update input value tracking for the whole radio
3748+
// button group in an effect or something (similar to #27024)
3749+
node.checked =
3750+
checked && typeof checked !== "function" && typeof checked !== "symbol";
37463751
}
37473752

37483753
if (
@@ -33817,7 +33822,7 @@ function createFiberRoot(
3381733822
return root;
3381833823
}
3381933824

33820-
var ReactVersion = "18.3.0-www-modern-b8e372cd";
33825+
var ReactVersion = "18.3.0-www-modern-752f226e";
3382133826

3382233827
function createPortal$1(
3382333828
children,

compiled/facebook-www/ReactDOM-prod.classic.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,8 @@ function updateInput(
10381038
null != defaultChecked &&
10391039
(element.defaultChecked = !!defaultChecked);
10401040
null != checked &&
1041-
element.checked !== !!checked &&
1042-
(element.checked = checked);
1041+
(element.checked =
1042+
checked && "function" !== typeof checked && "symbol" !== typeof checked);
10431043
null != name &&
10441044
"function" !== typeof name &&
10451045
"symbol" !== typeof name &&
@@ -16375,7 +16375,7 @@ Internals.Events = [
1637516375
var devToolsConfig$jscomp$inline_1779 = {
1637616376
findFiberByHostInstance: getClosestInstanceFromNode,
1637716377
bundleType: 0,
16378-
version: "18.3.0-www-classic-746b6ac2",
16378+
version: "18.3.0-www-classic-4ef77085",
1637916379
rendererPackageName: "react-dom"
1638016380
};
1638116381
var internals$jscomp$inline_2123 = {
@@ -16405,7 +16405,7 @@ var internals$jscomp$inline_2123 = {
1640516405
scheduleRoot: null,
1640616406
setRefreshHandler: null,
1640716407
getCurrentFiber: null,
16408-
reconcilerVersion: "18.3.0-www-classic-746b6ac2"
16408+
reconcilerVersion: "18.3.0-www-classic-4ef77085"
1640916409
};
1641016410
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1641116411
var hook$jscomp$inline_2124 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -16742,4 +16742,4 @@ exports.unstable_renderSubtreeIntoContainer = function (
1674216742
);
1674316743
};
1674416744
exports.unstable_runWithPriority = runWithPriority;
16745-
exports.version = "18.3.0-www-classic-746b6ac2";
16745+
exports.version = "18.3.0-www-classic-4ef77085";

compiled/facebook-www/ReactDOM-prod.modern.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,8 @@ function updateInput(
892892
null != defaultChecked &&
893893
(element.defaultChecked = !!defaultChecked);
894894
null != checked &&
895-
element.checked !== !!checked &&
896-
(element.checked = checked);
895+
(element.checked =
896+
checked && "function" !== typeof checked && "symbol" !== typeof checked);
897897
null != name &&
898898
"function" !== typeof name &&
899899
"symbol" !== typeof name &&
@@ -15897,7 +15897,7 @@ Internals.Events = [
1589715897
var devToolsConfig$jscomp$inline_1738 = {
1589815898
findFiberByHostInstance: getClosestInstanceFromNode,
1589915899
bundleType: 0,
15900-
version: "18.3.0-www-modern-84053073",
15900+
version: "18.3.0-www-modern-7f3360c5",
1590115901
rendererPackageName: "react-dom"
1590215902
};
1590315903
var internals$jscomp$inline_2087 = {
@@ -15928,7 +15928,7 @@ var internals$jscomp$inline_2087 = {
1592815928
scheduleRoot: null,
1592915929
setRefreshHandler: null,
1593015930
getCurrentFiber: null,
15931-
reconcilerVersion: "18.3.0-www-modern-84053073"
15931+
reconcilerVersion: "18.3.0-www-modern-7f3360c5"
1593215932
};
1593315933
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1593415934
var hook$jscomp$inline_2088 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -16193,4 +16193,4 @@ exports.unstable_createEventHandle = function (type, options) {
1619316193
return eventHandle;
1619416194
};
1619516195
exports.unstable_runWithPriority = runWithPriority;
16196-
exports.version = "18.3.0-www-modern-84053073";
16196+
exports.version = "18.3.0-www-modern-7f3360c5";

compiled/facebook-www/ReactDOM-profiling.classic.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,8 +1182,8 @@ function updateInput(
11821182
null != defaultChecked &&
11831183
(element.defaultChecked = !!defaultChecked);
11841184
null != checked &&
1185-
element.checked !== !!checked &&
1186-
(element.checked = checked);
1185+
(element.checked =
1186+
checked && "function" !== typeof checked && "symbol" !== typeof checked);
11871187
null != name &&
11881188
"function" !== typeof name &&
11891189
"symbol" !== typeof name &&
@@ -17150,7 +17150,7 @@ Internals.Events = [
1715017150
var devToolsConfig$jscomp$inline_1864 = {
1715117151
findFiberByHostInstance: getClosestInstanceFromNode,
1715217152
bundleType: 0,
17153-
version: "18.3.0-www-classic-5a92b4d5",
17153+
version: "18.3.0-www-classic-9802da3a",
1715417154
rendererPackageName: "react-dom"
1715517155
};
1715617156
(function (internals) {
@@ -17194,7 +17194,7 @@ var devToolsConfig$jscomp$inline_1864 = {
1719417194
scheduleRoot: null,
1719517195
setRefreshHandler: null,
1719617196
getCurrentFiber: null,
17197-
reconcilerVersion: "18.3.0-www-classic-5a92b4d5"
17197+
reconcilerVersion: "18.3.0-www-classic-9802da3a"
1719817198
});
1719917199
assign(Internals, {
1720017200
ReactBrowserEventEmitter: {
@@ -17518,7 +17518,7 @@ exports.unstable_renderSubtreeIntoContainer = function (
1751817518
);
1751917519
};
1752017520
exports.unstable_runWithPriority = runWithPriority;
17521-
exports.version = "18.3.0-www-classic-5a92b4d5";
17521+
exports.version = "18.3.0-www-classic-9802da3a";
1752217522

1752317523
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
1752417524
if (

compiled/facebook-www/ReactDOM-profiling.modern.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,8 +1036,8 @@ function updateInput(
10361036
null != defaultChecked &&
10371037
(element.defaultChecked = !!defaultChecked);
10381038
null != checked &&
1039-
element.checked !== !!checked &&
1040-
(element.checked = checked);
1039+
(element.checked =
1040+
checked && "function" !== typeof checked && "symbol" !== typeof checked);
10411041
null != name &&
10421042
"function" !== typeof name &&
10431043
"symbol" !== typeof name &&
@@ -16666,7 +16666,7 @@ Internals.Events = [
1666616666
var devToolsConfig$jscomp$inline_1823 = {
1666716667
findFiberByHostInstance: getClosestInstanceFromNode,
1666816668
bundleType: 0,
16669-
version: "18.3.0-www-modern-f998be57",
16669+
version: "18.3.0-www-modern-ea3ac45f",
1667016670
rendererPackageName: "react-dom"
1667116671
};
1667216672
(function (internals) {
@@ -16711,7 +16711,7 @@ var devToolsConfig$jscomp$inline_1823 = {
1671116711
scheduleRoot: null,
1671216712
setRefreshHandler: null,
1671316713
getCurrentFiber: null,
16714-
reconcilerVersion: "18.3.0-www-modern-f998be57"
16714+
reconcilerVersion: "18.3.0-www-modern-ea3ac45f"
1671516715
});
1671616716
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = Internals;
1671716717
exports.createPortal = function (children, container) {
@@ -16963,7 +16963,7 @@ exports.unstable_createEventHandle = function (type, options) {
1696316963
return eventHandle;
1696416964
};
1696516965
exports.unstable_runWithPriority = runWithPriority;
16966-
exports.version = "18.3.0-www-modern-f998be57";
16966+
exports.version = "18.3.0-www-modern-ea3ac45f";
1696716967

1696816968
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
1696916969
if (

0 commit comments

Comments
 (0)