Skip to content

Commit

Permalink
jsx: Remove unnecessary hasOwnProperty check
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.
  • Loading branch information
acdlite committed Apr 6, 2024
1 parent f86afca commit 9a2f7f4
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions packages/react/src/jsx/ReactJSXElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 9a2f7f4

Please sign in to comment.