Skip to content

Commit 947dd44

Browse files
committed
Update tracked value after resetting radio group (#27394)
Fixes #26876, I think. Review each commit separately (all assertions pass in main already, except the last assertInputTrackingIsClean in "should control radio buttons"). I'm actually a little confused on two things here: * All the isCheckedDirty assertions are true. But I don't think we set .checked unconditionally? So how does this happen? * #26876 (comment) claims that d962f35...1f248bd contains the faulty change, but it doesn't appear to change the restoration logic that I've touched here. (One difference outside restoration is that updateProperties did previously set `.checked` when `nextProp !== lastProp` whereas the new logic in updateInput is to set it when `node.checked !== !!checked`.) But it seems to me like we need this call here anyway, and if it fixes it then it fixes it? I think technically speaking we probably should do all the updateInput() calls and then all the updateValueIfChanged() calls—in particular I think if clicking A changed the checked radio button from B to C then the code as I have it would be incorrect, but that also seems unlikely so idk whether to care. cc @zhengjitf @Luk-z who did some investigation on the original issue DiffTrain build for [3c27178](3c27178)
1 parent ab9d541 commit 947dd44

15 files changed

+1604
-1536
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2b3d5826836ac59f8446281976762d594e55d97e
1+
3c27178a2f2c74f14d90613028e3929e1f06d830

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-996b7d13";
30+
var ReactVersion = "18.3.0-www-classic-2c91e2cd";
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-b27aac94";
618+
exports.version = "18.3.0-www-modern-a19b7375";

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-b5b87391";
629+
exports.version = "18.3.0-www-modern-4c57bafd";
630630

631631
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
632632
if (

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4104,10 +4104,7 @@ function restoreControlledInputState(element, props) {
41044104
"ReactDOMInput: Mixing React and non-React radio inputs with the " +
41054105
"same `name` is not supported."
41064106
);
4107-
} // We need update the tracked value on the named cousin since the value
4108-
// was changed but the input saw no event or value set
4109-
4110-
updateValueIfChanged(otherNode); // If this is a controlled radio button group, forcing the input that
4107+
} // If this is a controlled radio button group, forcing the input that
41114108
// was previously checked to update will cause it to be come re-checked
41124109
// as appropriate.
41134110

@@ -4121,6 +4118,17 @@ function restoreControlledInputState(element, props) {
41214118
otherProps.type,
41224119
otherProps.name
41234120
);
4121+
} // If any updateInput() call set .checked to true, an input in this group
4122+
// (often, `rootNode` itself) may have become unchecked
4123+
4124+
for (var _i = 0; _i < group.length; _i++) {
4125+
var _otherNode = group[_i];
4126+
4127+
if (_otherNode.form !== rootNode.form) {
4128+
continue;
4129+
}
4130+
4131+
updateValueIfChanged(_otherNode);
41244132
}
41254133
}
41264134
} // In Chrome, assigning defaultValue to certain input types triggers input validation.
@@ -34013,7 +34021,7 @@ function createFiberRoot(
3401334021
return root;
3401434022
}
3401534023

34016-
var ReactVersion = "18.3.0-www-classic-bb6c815e";
34024+
var ReactVersion = "18.3.0-www-classic-bfae45bc";
3401734025

3401834026
function createPortal$1(
3401934027
children,

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,10 +3946,7 @@ function restoreControlledInputState(element, props) {
39463946
"ReactDOMInput: Mixing React and non-React radio inputs with the " +
39473947
"same `name` is not supported."
39483948
);
3949-
} // We need update the tracked value on the named cousin since the value
3950-
// was changed but the input saw no event or value set
3951-
3952-
updateValueIfChanged(otherNode); // If this is a controlled radio button group, forcing the input that
3949+
} // If this is a controlled radio button group, forcing the input that
39533950
// was previously checked to update will cause it to be come re-checked
39543951
// as appropriate.
39553952

@@ -3963,6 +3960,17 @@ function restoreControlledInputState(element, props) {
39633960
otherProps.type,
39643961
otherProps.name
39653962
);
3963+
} // If any updateInput() call set .checked to true, an input in this group
3964+
// (often, `rootNode` itself) may have become unchecked
3965+
3966+
for (var _i = 0; _i < group.length; _i++) {
3967+
var _otherNode = group[_i];
3968+
3969+
if (_otherNode.form !== rootNode.form) {
3970+
continue;
3971+
}
3972+
3973+
updateValueIfChanged(_otherNode);
39663974
}
39673975
}
39683976
} // In Chrome, assigning defaultValue to certain input types triggers input validation.
@@ -33858,7 +33866,7 @@ function createFiberRoot(
3385833866
return root;
3385933867
}
3386033868

33861-
var ReactVersion = "18.3.0-www-modern-c7a0d8fc";
33869+
var ReactVersion = "18.3.0-www-modern-f84a446a";
3386233870

3386333871
function createPortal$1(
3386433872
children,

0 commit comments

Comments
 (0)