From aabb356a7e43bc3ec72b646248c6fb52fdd5c0ee Mon Sep 17 00:00:00 2001 From: acdlite Date: Mon, 8 Apr 2024 15:18:01 +0000 Subject: [PATCH] jsx: Remove unnecessary hasOwnProperty check (#28775) 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 [0b3b8a6a354b90fe76a9d82bb34487e5d2f71203](https://github.com/facebook/react/commit/0b3b8a6a354b90fe76a9d82bb34487e5d2f71203) --- compiled/facebook-www/JSXDEVRuntime-dev.classic.js | 7 ++----- compiled/facebook-www/JSXDEVRuntime-dev.modern.js | 7 ++----- compiled/facebook-www/REVISION | 2 +- compiled/facebook-www/React-dev.classic.js | 9 +++------ compiled/facebook-www/React-dev.modern.js | 9 +++------ compiled/facebook-www/React-prod.classic.js | 7 +++---- compiled/facebook-www/React-prod.modern.js | 7 +++---- compiled/facebook-www/React-profiling.classic.js | 7 +++---- compiled/facebook-www/React-profiling.modern.js | 7 +++---- compiled/facebook-www/ReactServer-dev.modern.js | 9 +++------ compiled/facebook-www/ReactServer-prod.modern.js | 7 +++---- 11 files changed, 29 insertions(+), 49 deletions(-) diff --git a/compiled/facebook-www/JSXDEVRuntime-dev.classic.js b/compiled/facebook-www/JSXDEVRuntime-dev.classic.js index 8a69860669..dfaa72c78f 100644 --- a/compiled/facebook-www/JSXDEVRuntime-dev.classic.js +++ b/compiled/facebook-www/JSXDEVRuntime-dev.classic.js @@ -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], diff --git a/compiled/facebook-www/JSXDEVRuntime-dev.modern.js b/compiled/facebook-www/JSXDEVRuntime-dev.modern.js index bda96ae087..7e5f1724fd 100644 --- a/compiled/facebook-www/JSXDEVRuntime-dev.modern.js +++ b/compiled/facebook-www/JSXDEVRuntime-dev.modern.js @@ -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], diff --git a/compiled/facebook-www/REVISION b/compiled/facebook-www/REVISION index ef8c9de32d..89822afbc5 100644 --- a/compiled/facebook-www/REVISION +++ b/compiled/facebook-www/REVISION @@ -1 +1 @@ -2acfb7b60922bdc8376dd144ca7bc532df78254b +0b3b8a6a354b90fe76a9d82bb34487e5d2f71203 diff --git a/compiled/facebook-www/React-dev.classic.js b/compiled/facebook-www/React-dev.classic.js index 81f0458c13..4083348c90 100644 --- a/compiled/facebook-www/React-dev.classic.js +++ b/compiled/facebook-www/React-dev.classic.js @@ -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, @@ -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], diff --git a/compiled/facebook-www/React-dev.modern.js b/compiled/facebook-www/React-dev.modern.js index 0dd55f2e82..6c8790db9d 100644 --- a/compiled/facebook-www/React-dev.modern.js +++ b/compiled/facebook-www/React-dev.modern.js @@ -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, @@ -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], diff --git a/compiled/facebook-www/React-prod.classic.js b/compiled/facebook-www/React-prod.classic.js index c45201e53a..59c83ad220 100644 --- a/compiled/facebook-www/React-prod.classic.js +++ b/compiled/facebook-www/React-prod.classic.js @@ -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], @@ -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"; diff --git a/compiled/facebook-www/React-prod.modern.js b/compiled/facebook-www/React-prod.modern.js index b0d40fd745..98a7961afc 100644 --- a/compiled/facebook-www/React-prod.modern.js +++ b/compiled/facebook-www/React-prod.modern.js @@ -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], @@ -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"; diff --git a/compiled/facebook-www/React-profiling.classic.js b/compiled/facebook-www/React-profiling.classic.js index 3c663e08d4..911af10b78 100644 --- a/compiled/facebook-www/React-profiling.classic.js +++ b/compiled/facebook-www/React-profiling.classic.js @@ -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], @@ -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 && diff --git a/compiled/facebook-www/React-profiling.modern.js b/compiled/facebook-www/React-profiling.modern.js index 408a871209..ba597845b8 100644 --- a/compiled/facebook-www/React-profiling.modern.js +++ b/compiled/facebook-www/React-profiling.modern.js @@ -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], @@ -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 && diff --git a/compiled/facebook-www/ReactServer-dev.modern.js b/compiled/facebook-www/ReactServer-dev.modern.js index a91497aae9..cfe9a58eaa 100644 --- a/compiled/facebook-www/ReactServer-dev.modern.js +++ b/compiled/facebook-www/ReactServer-dev.modern.js @@ -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], @@ -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 = { diff --git a/compiled/facebook-www/ReactServer-prod.modern.js b/compiled/facebook-www/ReactServer-prod.modern.js index b2161e1d11..e2986473cd 100644 --- a/compiled/facebook-www/ReactServer-prod.modern.js +++ b/compiled/facebook-www/ReactServer-prod.modern.js @@ -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], @@ -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";