@samitouri / QOS-React-2 / commits / 0b3b8a6a35

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.

Andrew Clark committed Apr 8, 2024 at 11:12 UTC 0b3b8a6a354b90fe76a9d82bb34487e5d2f71203
1 file changed +4 -12
packages/react/src/jsx/ReactJSXElement.js
+4 -12
@@ -364,12 +364,8 @@ export function jsxProd(type, config, maybeKey) {
364 // because in V8 it will deopt the object to dictionary mode.
365 props = {};
366 for (const propName in config) {
367 - if (
368 - hasOwnProperty.call(config, propName) &&
369 - // Skip over reserved prop names
370 - propName !== 'key' &&
371 - (enableRefAsProp || propName !== 'ref')
372 - ) {
367 + // Skip over reserved prop names
368 + if (propName !== 'key' && (enableRefAsProp || propName !== 'ref')) {
369 if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
370 props.ref = coerceStringRef(
371 config[propName],
@@ -603,12 +599,8 @@ export function jsxDEV(type, config, maybeKey, isStaticChildren, source, self) {
599 // because in V8 it will deopt the object to dictionary mode.
600 props = {};
601 for (const propName in config) {
606 - if (
607 - hasOwnProperty.call(config, propName) &&
608 - // Skip over reserved prop names
609 - propName !== 'key' &&
610 - (enableRefAsProp || propName !== 'ref')
611 - ) {
602 + // Skip over reserved prop names
603 + if (propName !== 'key' && (enableRefAsProp || propName !== 'ref')) {
604 if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
605 props.ref = coerceStringRef(
606 config[propName],