Skip to content

Commit

Permalink
Fix input tracking bug (#26627)
Browse files Browse the repository at this point in the history
In
2019ddc,
we changed to set .defaultValue before .value on updates. In some cases,
setting .defaultValue causes .value to change, and since we only set
.value if it has the wrong value, this resulted in us not assigning to
.value, which resulted in inputValueTracking not knowing the right
value. See new test added.

My fix here is to (a) move the value setting back up first and (b)
narrowing the fix in the aforementioned PR to newly remove the value
attribute only if it defaultValue was previously present in props.

The second half is necessary because for types where the value property
and attribute are indelibly linked (hidden checkbox radio submit image
reset button, i.e. spec modes default or default/on from
https://html.spec.whatwg.org/multipage/input.html#dom-input-value-default),
we can't remove the value attribute after setting .value, because that
will undo the assignment we just did! That is, not having (b) makes all
of those types fail to handle updating props.value.

This code is incredibly hard to think about but I think this is right
(or at least, as right as the old code was) because we set .value here
only if the nextProps.value != null, and we now remove defaultValue only
if lastProps.defaultValue != null. These can't happen at the same time
because we have long warned if value and defaultValue are simultaneously
specified, and also if a component switches between controlled and
uncontrolled.

Also, it fixes the test in #26626.

DiffTrain build for commit b433c37.
  • Loading branch information
sophiebits committed Apr 18, 2023
1 parent ab60b82 commit 812b950
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23745,7 +23745,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-next-d962f35ca-20230418";
var ReactVersion = "18.3.0-next-b433c379d-20230418";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8587,7 +8587,7 @@ var devToolsConfig$jscomp$inline_1023 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-next-d962f35ca-20230418",
version: "18.3.0-next-b433c379d-20230418",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1206 = {
Expand Down Expand Up @@ -8618,7 +8618,7 @@ var internals$jscomp$inline_1206 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d962f35ca-20230418"
reconcilerVersion: "18.3.0-next-b433c379d-20230418"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1207 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9013,7 +9013,7 @@ var devToolsConfig$jscomp$inline_1065 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-next-d962f35ca-20230418",
version: "18.3.0-next-b433c379d-20230418",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1247 = {
Expand Down Expand Up @@ -9044,7 +9044,7 @@ var internals$jscomp$inline_1247 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d962f35ca-20230418"
reconcilerVersion: "18.3.0-next-b433c379d-20230418"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1248 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-next-d962f35ca-20230418";
var ReactVersion = "18.3.0-next-b433c379d-20230418";

// ATTENTION
// When adding new symbols to this file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,4 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-next-d962f35ca-20230418";
exports.version = "18.3.0-next-b433c379d-20230418";
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-next-d962f35ca-20230418";
exports.version = "18.3.0-next-b433c379d-20230418";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d962f35cac4e1b9e4c6d9320e60ca51037680296
b433c379d55d9684945217c7d375de1082a1abb8
Original file line number Diff line number Diff line change
Expand Up @@ -27052,7 +27052,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-next-d962f35ca-20230418";
var ReactVersion = "18.3.0-next-b433c379d-20230418";

function createPortal$1(
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9456,7 +9456,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1047 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-next-d962f35ca-20230418",
version: "18.3.0-next-b433c379d-20230418",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -9498,7 +9498,7 @@ var internals$jscomp$inline_1276 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d962f35ca-20230418"
reconcilerVersion: "18.3.0-next-b433c379d-20230418"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1277 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10165,7 +10165,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1125 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-next-d962f35ca-20230418",
version: "18.3.0-next-b433c379d-20230418",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -10220,7 +10220,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d962f35ca-20230418"
reconcilerVersion: "18.3.0-next-b433c379d-20230418"
});
exports.createPortal = function (children, containerTag) {
return createPortal$1(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27565,7 +27565,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-next-d962f35ca-20230418";
var ReactVersion = "18.3.0-next-b433c379d-20230418";

function createPortal$1(
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9715,7 +9715,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1102 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-next-d962f35ca-20230418",
version: "18.3.0-next-b433c379d-20230418",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -9757,7 +9757,7 @@ var internals$jscomp$inline_1345 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d962f35ca-20230418"
reconcilerVersion: "18.3.0-next-b433c379d-20230418"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1346 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10424,7 +10424,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1180 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-next-d962f35ca-20230418",
version: "18.3.0-next-b433c379d-20230418",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
Expand Down Expand Up @@ -10479,7 +10479,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-d962f35ca-20230418"
reconcilerVersion: "18.3.0-next-b433c379d-20230418"
});
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
computeComponentStackForErrorReporting: function (reactTag) {
Expand Down

0 comments on commit 812b950

Please sign in to comment.