From 6715bb1456444f21bb759b59194794e069ee30f9 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Mon, 8 Apr 2024 11:12:40 -0400 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. --- packages/react/src/jsx/ReactJSXElement.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/react/src/jsx/ReactJSXElement.js b/packages/react/src/jsx/ReactJSXElement.js index 1ef9cea6d3e75..2dd64c207e4e0 100644 --- a/packages/react/src/jsx/ReactJSXElement.js +++ b/packages/react/src/jsx/ReactJSXElement.js @@ -364,12 +364,8 @@ export function jsxProd(type, config, maybeKey) { // because in V8 it will deopt the object to dictionary mode. props = {}; for (const 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], @@ -603,12 +599,8 @@ export function jsxDEV(type, config, maybeKey, isStaticChildren, source, self) { // because in V8 it will deopt the object to dictionary mode. props = {}; for (const 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],