Skip to content

Commit

Permalink
Don't update textarea defaultValue and input checked unnecessarily (#…
Browse files Browse the repository at this point in the history
…26580)

In #26573 I changed it so that textareas get their defaultValue reset if
you don't specify one.

However, the way that was implemented, it always set it for any update
even if it hasn't changed.

We have a test for that, but that test only works if no properties
update at all so that no update was scheduled. This fixes the test so
that it updates some unrelated prop.

I also found a test for `checked` that needed a similar fix.

Interestingly, we don't do this deduping for `defaultValue` or
`defaultChecked` on inputs and there's no test for that.

DiffTrain build for [9a9da77](9a9da77)
  • Loading branch information
sebmarkbage committed Apr 10, 2023
1 parent bdd6ae3 commit 75825ff
Show file tree
Hide file tree
Showing 15 changed files with 362 additions and 312 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e5146cb5250be1a4e66511af91549859b36ed488
9a9da7721e5b73a8af242807e463e2af842c58ee
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-modern-a9e6dcdb";
var ReactVersion = "18.3.0-www-modern-bfaf8fe7";

// ATTENTION
// When adding new symbols to this file,
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-classic-6b173260";
var ReactVersion = "18.3.0-www-classic-4f49fe42";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -9737,7 +9737,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-modern-e257717e",
version: "18.3.0-www-modern-3b22d407",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1324 = {
Expand Down Expand Up @@ -9768,7 +9768,7 @@ var internals$jscomp$inline_1324 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-e257717e"
reconcilerVersion: "18.3.0-www-modern-3b22d407"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1325 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
27 changes: 16 additions & 11 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3806,7 +3806,7 @@ function updateInputChecked(element, props) {
var node = element;
var checked = props.checked;

if (checked != null) {
if (checked != null && node.checked !== !!checked) {
node.checked = checked;
}
}
Expand Down Expand Up @@ -4360,13 +4360,6 @@ function validateTextareaProps(element, props) {
function updateTextarea(element, props) {
var node = element;
var value = getToStringValue(props.value);
var defaultValue = getToStringValue(props.defaultValue);

if (defaultValue != null) {
node.defaultValue = toString(defaultValue);
} else {
node.defaultValue = "";
}

if (value != null) {
// Cast `value` to a string to ensure the value is set correctly. While
Expand All @@ -4377,10 +4370,22 @@ function updateTextarea(element, props) {
node.value = newValue;
} // TOOO: This should respect disableInputAttributeSyncing flag.

if (props.defaultValue == null && node.defaultValue !== newValue) {
node.defaultValue = newValue;
if (props.defaultValue == null) {
if (node.defaultValue !== newValue) {
node.defaultValue = newValue;
}

return;
}
}

var defaultValue = getToStringValue(props.defaultValue);

if (defaultValue != null) {
node.defaultValue = toString(defaultValue);
} else {
node.defaultValue = "";
}
}
function initTextarea(element, props) {
var node = element;
Expand Down Expand Up @@ -33343,7 +33348,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-classic-6714ccf8";
var ReactVersion = "18.3.0-www-classic-1bf554dd";

function createPortal$1(
children,
Expand Down
27 changes: 16 additions & 11 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -3640,7 +3640,7 @@ function updateInputChecked(element, props) {
var node = element;
var checked = props.checked;

if (checked != null) {
if (checked != null && node.checked !== !!checked) {
node.checked = checked;
}
}
Expand Down Expand Up @@ -4194,13 +4194,6 @@ function validateTextareaProps(element, props) {
function updateTextarea(element, props) {
var node = element;
var value = getToStringValue(props.value);
var defaultValue = getToStringValue(props.defaultValue);

if (defaultValue != null) {
node.defaultValue = toString(defaultValue);
} else {
node.defaultValue = "";
}

if (value != null) {
// Cast `value` to a string to ensure the value is set correctly. While
Expand All @@ -4211,10 +4204,22 @@ function updateTextarea(element, props) {
node.value = newValue;
} // TOOO: This should respect disableInputAttributeSyncing flag.

if (props.defaultValue == null && node.defaultValue !== newValue) {
node.defaultValue = newValue;
if (props.defaultValue == null) {
if (node.defaultValue !== newValue) {
node.defaultValue = newValue;
}

return;
}
}

var defaultValue = getToStringValue(props.defaultValue);

if (defaultValue != null) {
node.defaultValue = toString(defaultValue);
} else {
node.defaultValue = "";
}
}
function initTextarea(element, props) {
var node = element;
Expand Down Expand Up @@ -33179,7 +33184,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-modern-e257717e";
var ReactVersion = "18.3.0-www-modern-3b22d407";

function createPortal$1(
children,
Expand Down
97 changes: 51 additions & 46 deletions compiled/facebook-www/ReactDOM-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,10 @@ function getActiveElement(doc) {
return doc.body;
}
}
function updateInputChecked(element, props) {
props = props.checked;
null != props && element.checked !== !!props && (element.checked = props);
}
function updateInput(element, props) {
var value = getToStringValue(props.value),
type = props.type;
Expand All @@ -996,8 +1000,7 @@ function updateInput(element, props) {
: null == props.checked &&
null != props.defaultChecked &&
(element.defaultChecked = !!props.defaultChecked);
props = props.checked;
null != props && (element.checked = props);
updateInputChecked(element, props);
if (null != value)
if ("number" === type) {
if ((0 === value && "" === element.value) || element.value != value)
Expand Down Expand Up @@ -1077,15 +1080,18 @@ function updateOptions(node, multiple, propValue, setDefaultSelected) {
}
}
function updateTextarea(element, props) {
var value = getToStringValue(props.value),
defaultValue = getToStringValue(props.defaultValue);
element.defaultValue = null != defaultValue ? "" + defaultValue : "";
null != value &&
var value = getToStringValue(props.value);
if (
null != value &&
((value = "" + value),
value !== element.value && (element.value = value),
null == props.defaultValue &&
element.defaultValue !== value &&
(element.defaultValue = value));
null == props.defaultValue)
) {
element.defaultValue !== value && (element.defaultValue = value);
return;
}
props = getToStringValue(props.defaultValue);
element.defaultValue = null != props ? "" + props : "";
}
function initTextarea(element, props) {
var initialValue = props.value;
Expand Down Expand Up @@ -12560,14 +12566,14 @@ var isInputEventSupported = !1;
if (canUseDOM) {
var JSCompiler_inline_result$jscomp$332;
if (canUseDOM) {
var isSupported$jscomp$inline_1562 = "oninput" in document;
if (!isSupported$jscomp$inline_1562) {
var element$jscomp$inline_1563 = document.createElement("div");
element$jscomp$inline_1563.setAttribute("oninput", "return;");
isSupported$jscomp$inline_1562 =
"function" === typeof element$jscomp$inline_1563.oninput;
var isSupported$jscomp$inline_1557 = "oninput" in document;
if (!isSupported$jscomp$inline_1557) {
var element$jscomp$inline_1558 = document.createElement("div");
element$jscomp$inline_1558.setAttribute("oninput", "return;");
isSupported$jscomp$inline_1557 =
"function" === typeof element$jscomp$inline_1558.oninput;
}
JSCompiler_inline_result$jscomp$332 = isSupported$jscomp$inline_1562;
JSCompiler_inline_result$jscomp$332 = isSupported$jscomp$inline_1557;
} else JSCompiler_inline_result$jscomp$332 = !1;
isInputEventSupported =
JSCompiler_inline_result$jscomp$332 &&
Expand Down Expand Up @@ -12879,20 +12885,20 @@ function registerSimpleEvent(domEventName, reactName) {
registerTwoPhaseEvent(reactName, [domEventName]);
}
for (
var i$jscomp$inline_1603 = 0;
i$jscomp$inline_1603 < simpleEventPluginEvents.length;
i$jscomp$inline_1603++
var i$jscomp$inline_1598 = 0;
i$jscomp$inline_1598 < simpleEventPluginEvents.length;
i$jscomp$inline_1598++
) {
var eventName$jscomp$inline_1604 =
simpleEventPluginEvents[i$jscomp$inline_1603],
domEventName$jscomp$inline_1605 =
eventName$jscomp$inline_1604.toLowerCase(),
capitalizedEvent$jscomp$inline_1606 =
eventName$jscomp$inline_1604[0].toUpperCase() +
eventName$jscomp$inline_1604.slice(1);
var eventName$jscomp$inline_1599 =
simpleEventPluginEvents[i$jscomp$inline_1598],
domEventName$jscomp$inline_1600 =
eventName$jscomp$inline_1599.toLowerCase(),
capitalizedEvent$jscomp$inline_1601 =
eventName$jscomp$inline_1599[0].toUpperCase() +
eventName$jscomp$inline_1599.slice(1);
registerSimpleEvent(
domEventName$jscomp$inline_1605,
"on" + capitalizedEvent$jscomp$inline_1606
domEventName$jscomp$inline_1600,
"on" + capitalizedEvent$jscomp$inline_1601
);
}
registerSimpleEvent(ANIMATION_END, "onAnimationEnd");
Expand Down Expand Up @@ -14246,8 +14252,7 @@ function updateProperties(
case "input":
"radio" === nextProps.type &&
null != nextProps.name &&
((lastProps = nextProps.checked),
null != lastProps && (domElement.checked = lastProps));
updateInputChecked(domElement, nextProps);
for (lastProps = 0; lastProps < updatePayload.length; lastProps += 2) {
var propKey = updatePayload[lastProps],
propValue = updatePayload[lastProps + 1];
Expand Down Expand Up @@ -16047,17 +16052,17 @@ Internals.Events = [
restoreStateIfNeeded,
batchedUpdates$1
];
var devToolsConfig$jscomp$inline_1822 = {
var devToolsConfig$jscomp$inline_1812 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-classic-42d0ecd9",
version: "18.3.0-www-classic-2bdbd8ab",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2191 = {
bundleType: devToolsConfig$jscomp$inline_1822.bundleType,
version: devToolsConfig$jscomp$inline_1822.version,
rendererPackageName: devToolsConfig$jscomp$inline_1822.rendererPackageName,
rendererConfig: devToolsConfig$jscomp$inline_1822.rendererConfig,
var internals$jscomp$inline_2181 = {
bundleType: devToolsConfig$jscomp$inline_1812.bundleType,
version: devToolsConfig$jscomp$inline_1812.version,
rendererPackageName: devToolsConfig$jscomp$inline_1812.rendererPackageName,
rendererConfig: devToolsConfig$jscomp$inline_1812.rendererConfig,
overrideHookState: null,
overrideHookStateDeletePath: null,
overrideHookStateRenamePath: null,
Expand All @@ -16073,26 +16078,26 @@ var internals$jscomp$inline_2191 = {
return null === fiber ? null : fiber.stateNode;
},
findFiberByHostInstance:
devToolsConfig$jscomp$inline_1822.findFiberByHostInstance ||
devToolsConfig$jscomp$inline_1812.findFiberByHostInstance ||
emptyFindFiberByHostInstance,
findHostInstancesForRefresh: null,
scheduleRefresh: null,
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-classic-42d0ecd9"
reconcilerVersion: "18.3.0-www-classic-2bdbd8ab"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2192 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
var hook$jscomp$inline_2182 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
if (
!hook$jscomp$inline_2192.isDisabled &&
hook$jscomp$inline_2192.supportsFiber
!hook$jscomp$inline_2182.isDisabled &&
hook$jscomp$inline_2182.supportsFiber
)
try {
(rendererID = hook$jscomp$inline_2192.inject(
internals$jscomp$inline_2191
(rendererID = hook$jscomp$inline_2182.inject(
internals$jscomp$inline_2181
)),
(injectedHook = hook$jscomp$inline_2192);
(injectedHook = hook$jscomp$inline_2182);
} catch (err) {}
}
assign(Internals, {
Expand Down Expand Up @@ -16320,4 +16325,4 @@ exports.unstable_renderSubtreeIntoContainer = function (
);
};
exports.unstable_runWithPriority = runWithPriority;
exports.version = "18.3.0-www-classic-42d0ecd9";
exports.version = "18.3.0-www-classic-2bdbd8ab";
Loading

0 comments on commit 75825ff

Please sign in to comment.