Skip to content

Commit

Permalink
jsx: Remove unnecessary hasOwnProperty check (#28775)
Browse files Browse the repository at this point in the history
Follow up to #28768.

The modern JSX runtime (`jsx`) does not need to check if each prop is a
direct property with `hasOwnProperty` because the compiler always passes
a plain object.

I'll leave the check in the old JSX runtime (`createElement`) since that
one can be called manually with any kind of object, and if there were
old user code that relied on this for some reason, it would be using
that runtime.

DiffTrain build for [0b3b8a6](0b3b8a6)
  • Loading branch information
acdlite committed Apr 8, 2024
1 parent c093e5b commit aabb356
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 49 deletions.
7 changes: 2 additions & 5 deletions compiled/facebook-www/JSXDEVRuntime-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1410,11 +1410,8 @@ if (__DEV__) {
props = {};

for (var propName in config) {
if (
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" &&
(enableRefAsProp || propName !== "ref")
) {
// Skip over reserved prop names
if (propName !== "key" && (enableRefAsProp || propName !== "ref")) {
if (enableRefAsProp && !disableStringRefs && propName === "ref") {
props.ref = coerceStringRef(
config[propName],
Expand Down
7 changes: 2 additions & 5 deletions compiled/facebook-www/JSXDEVRuntime-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1412,11 +1412,8 @@ if (__DEV__) {
props = {};

for (var propName in config) {
if (
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" &&
(enableRefAsProp || propName !== "ref")
) {
// Skip over reserved prop names
if (propName !== "key" && (enableRefAsProp || propName !== "ref")) {
if (enableRefAsProp && !disableStringRefs && propName === "ref") {
props.ref = coerceStringRef(
config[propName],
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2acfb7b60922bdc8376dd144ca7bc532df78254b
0b3b8a6a354b90fe76a9d82bb34487e5d2f71203
9 changes: 3 additions & 6 deletions compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "19.0.0-www-classic-4511ca3e";
var ReactVersion = "19.0.0-www-classic-87084f69";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -1818,11 +1818,8 @@ if (__DEV__) {
props = {};

for (var propName in config) {
if (
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" &&
(enableRefAsProp || propName !== "ref")
) {
// Skip over reserved prop names
if (propName !== "key" && (enableRefAsProp || propName !== "ref")) {
if (enableRefAsProp && !disableStringRefs && propName === "ref") {
props.ref = coerceStringRef(
config[propName],
Expand Down
9 changes: 3 additions & 6 deletions compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "19.0.0-www-modern-8e3891bc";
var ReactVersion = "19.0.0-www-modern-7116ae62";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -1820,11 +1820,8 @@ if (__DEV__) {
props = {};

for (var propName in config) {
if (
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" &&
(enableRefAsProp || propName !== "ref")
) {
// Skip over reserved prop names
if (propName !== "key" && (enableRefAsProp || propName !== "ref")) {
if (enableRefAsProp && !disableStringRefs && propName === "ref") {
props.ref = coerceStringRef(
config[propName],
Expand Down
7 changes: 3 additions & 4 deletions compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ function jsxProd(type, config, maybeKey) {
(ref = coerceStringRef(ref, ReactCurrentOwner.current, type)));
maybeKey = {};
for (var propName in config)
hasOwnProperty.call(config, propName) &&
"key" !== propName &&
(enableRefAsProp || "ref" !== propName) &&
"key" === propName ||
(!enableRefAsProp && "ref" === propName) ||
(enableRefAsProp && "ref" === propName
? (maybeKey.ref = coerceStringRef(
config[propName],
Expand Down Expand Up @@ -704,4 +703,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "19.0.0-www-classic-36e8d411";
exports.version = "19.0.0-www-classic-544fd05e";
7 changes: 3 additions & 4 deletions compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ function jsxProd(type, config, maybeKey) {
(ref = coerceStringRef(ref, ReactCurrentOwner.current, type)));
maybeKey = {};
for (var propName in config)
hasOwnProperty.call(config, propName) &&
"key" !== propName &&
(enableRefAsProp || "ref" !== propName) &&
"key" === propName ||
(!enableRefAsProp && "ref" === propName) ||
(enableRefAsProp && "ref" === propName
? (maybeKey.ref = coerceStringRef(
config[propName],
Expand Down Expand Up @@ -704,4 +703,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "19.0.0-www-modern-36e8d411";
exports.version = "19.0.0-www-modern-544fd05e";
7 changes: 3 additions & 4 deletions compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ function jsxProd(type, config, maybeKey) {
(ref = coerceStringRef(ref, ReactCurrentOwner.current, type)));
maybeKey = {};
for (var propName in config)
hasOwnProperty.call(config, propName) &&
"key" !== propName &&
(enableRefAsProp || "ref" !== propName) &&
"key" === propName ||
(!enableRefAsProp && "ref" === propName) ||
(enableRefAsProp && "ref" === propName
? (maybeKey.ref = coerceStringRef(
config[propName],
Expand Down Expand Up @@ -708,7 +707,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "19.0.0-www-classic-718fc0c7";
exports.version = "19.0.0-www-classic-c3069b6b";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
7 changes: 3 additions & 4 deletions compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ function jsxProd(type, config, maybeKey) {
(ref = coerceStringRef(ref, ReactCurrentOwner.current, type)));
maybeKey = {};
for (var propName in config)
hasOwnProperty.call(config, propName) &&
"key" !== propName &&
(enableRefAsProp || "ref" !== propName) &&
"key" === propName ||
(!enableRefAsProp && "ref" === propName) ||
(enableRefAsProp && "ref" === propName
? (maybeKey.ref = coerceStringRef(
config[propName],
Expand Down Expand Up @@ -708,7 +707,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "19.0.0-www-modern-718fc0c7";
exports.version = "19.0.0-www-modern-c3069b6b";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
9 changes: 3 additions & 6 deletions compiled/facebook-www/ReactServer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1530,11 +1530,8 @@ if (__DEV__) {
props = {};

for (var propName in config) {
if (
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" &&
(enableRefAsProp || propName !== "ref")
) {
// Skip over reserved prop names
if (propName !== "key" && (enableRefAsProp || propName !== "ref")) {
if (enableRefAsProp && !disableStringRefs && propName === "ref") {
props.ref = coerceStringRef(
config[propName],
Expand Down Expand Up @@ -3134,7 +3131,7 @@ if (__DEV__) {

function noop() {}

var ReactVersion = "19.0.0-www-modern-4e2ff20e";
var ReactVersion = "19.0.0-www-modern-c9d5711a";

// Patch fetch
var Children = {
Expand Down
7 changes: 3 additions & 4 deletions compiled/facebook-www/ReactServer-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ function jsxProd(type, config, maybeKey) {
(ref = coerceStringRef(ref, ReactCurrentOwner.current, type)));
maybeKey = {};
for (var propName in config)
hasOwnProperty.call(config, propName) &&
"key" !== propName &&
(enableRefAsProp || "ref" !== propName) &&
"key" === propName ||
(!enableRefAsProp && "ref" === propName) ||
(enableRefAsProp && "ref" === propName
? (maybeKey.ref = coerceStringRef(
config[propName],
Expand Down Expand Up @@ -602,4 +601,4 @@ exports.useId = function () {
exports.useMemo = function (create, deps) {
return ReactCurrentDispatcher.current.useMemo(create, deps);
};
exports.version = "19.0.0-www-modern-ea5b7988";
exports.version = "19.0.0-www-modern-9b5f5653";

0 comments on commit aabb356

Please sign in to comment.