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

+66
-46
lines changed

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 (

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,8 +4033,13 @@ function updateInput(
40334033
}
40344034
}
40354035

4036-
if (checked != null && node.checked !== !!checked) {
4037-
node.checked = checked;
4036+
if (checked != null) {
4037+
// Important to set this even if it's not a change in order to update input
4038+
// value tracking with radio buttons
4039+
// TODO: Should really update input value tracking for the whole radio
4040+
// button group in an effect or something (similar to #27024)
4041+
node.checked =
4042+
checked && typeof checked !== "function" && typeof checked !== "symbol";
40384043
}
40394044

40404045
if (
@@ -34589,7 +34594,7 @@ function createFiberRoot(
3458934594
return root;
3459034595
}
3459134596

34592-
var ReactVersion = "18.3.0-www-classic-49f3ea5b";
34597+
var ReactVersion = "18.3.0-www-classic-ffc4f8d2";
3459334598

3459434599
function createPortal$1(
3459534600
children,

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,8 +3875,13 @@ function updateInput(
38753875
}
38763876
}
38773877

3878-
if (checked != null && node.checked !== !!checked) {
3879-
node.checked = checked;
3878+
if (checked != null) {
3879+
// Important to set this even if it's not a change in order to update input
3880+
// value tracking with radio buttons
3881+
// TODO: Should really update input value tracking for the whole radio
3882+
// button group in an effect or something (similar to #27024)
3883+
node.checked =
3884+
checked && typeof checked !== "function" && typeof checked !== "symbol";
38803885
}
38813886

38823887
if (
@@ -34434,7 +34439,7 @@ function createFiberRoot(
3443434439
return root;
3443534440
}
3443634441

34437-
var ReactVersion = "18.3.0-www-modern-96829b2e";
34442+
var ReactVersion = "18.3.0-www-modern-dc699db3";
3443834443

3443934444
function createPortal$1(
3444034445
children,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,8 +1124,8 @@ function updateInput(
11241124
null != defaultChecked &&
11251125
(element.defaultChecked = !!defaultChecked);
11261126
null != checked &&
1127-
element.checked !== !!checked &&
1128-
(element.checked = checked);
1127+
(element.checked =
1128+
checked && "function" !== typeof checked && "symbol" !== typeof checked);
11291129
null != name &&
11301130
"function" !== typeof name &&
11311131
"symbol" !== typeof name &&
@@ -16704,7 +16704,7 @@ Internals.Events = [
1670416704
var devToolsConfig$jscomp$inline_1808 = {
1670516705
findFiberByHostInstance: getClosestInstanceFromNode,
1670616706
bundleType: 0,
16707-
version: "18.3.0-www-classic-591e80f2",
16707+
version: "18.3.0-www-classic-ff54ec02",
1670816708
rendererPackageName: "react-dom"
1670916709
};
1671016710
var internals$jscomp$inline_2157 = {
@@ -16734,7 +16734,7 @@ var internals$jscomp$inline_2157 = {
1673416734
scheduleRoot: null,
1673516735
setRefreshHandler: null,
1673616736
getCurrentFiber: null,
16737-
reconcilerVersion: "18.3.0-www-classic-591e80f2"
16737+
reconcilerVersion: "18.3.0-www-classic-ff54ec02"
1673816738
};
1673916739
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1674016740
var hook$jscomp$inline_2158 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17222,4 +17222,4 @@ exports.unstable_renderSubtreeIntoContainer = function (
1722217222
);
1722317223
};
1722417224
exports.unstable_runWithPriority = runWithPriority;
17225-
exports.version = "18.3.0-www-classic-591e80f2";
17225+
exports.version = "18.3.0-www-classic-ff54ec02";

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,8 +1033,8 @@ function updateInput(
10331033
null != defaultChecked &&
10341034
(element.defaultChecked = !!defaultChecked);
10351035
null != checked &&
1036-
element.checked !== !!checked &&
1037-
(element.checked = checked);
1036+
(element.checked =
1037+
checked && "function" !== typeof checked && "symbol" !== typeof checked);
10381038
null != name &&
10391039
"function" !== typeof name &&
10401040
"symbol" !== typeof name &&
@@ -16281,7 +16281,7 @@ Internals.Events = [
1628116281
var devToolsConfig$jscomp$inline_1767 = {
1628216282
findFiberByHostInstance: getClosestInstanceFromNode,
1628316283
bundleType: 0,
16284-
version: "18.3.0-www-modern-1a772a6d",
16284+
version: "18.3.0-www-modern-622fc29e",
1628516285
rendererPackageName: "react-dom"
1628616286
};
1628716287
var internals$jscomp$inline_2121 = {
@@ -16312,7 +16312,7 @@ var internals$jscomp$inline_2121 = {
1631216312
scheduleRoot: null,
1631316313
setRefreshHandler: null,
1631416314
getCurrentFiber: null,
16315-
reconcilerVersion: "18.3.0-www-modern-1a772a6d"
16315+
reconcilerVersion: "18.3.0-www-modern-622fc29e"
1631616316
};
1631716317
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1631816318
var hook$jscomp$inline_2122 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -16728,4 +16728,4 @@ exports.unstable_createEventHandle = function (type, options) {
1672816728
return eventHandle;
1672916729
};
1673016730
exports.unstable_runWithPriority = runWithPriority;
16731-
exports.version = "18.3.0-www-modern-1a772a6d";
16731+
exports.version = "18.3.0-www-modern-622fc29e";

0 commit comments

Comments
 (0)