Skip to content

Commit

Permalink
jsx(): Inline reserved prop checks (#28262)
Browse files Browse the repository at this point in the history
The JSX runtime (both the new one and the classic createElement runtime)
check for reserved props like `key` and `ref` by doing a lookup in a
plain object map with `hasOwnProperty`.

There are only a few reserved props so this inlines the checks instead.

DiffTrain build for [1beb941](1beb941)
  • Loading branch information
acdlite committed Feb 7, 2024
1 parent e46929f commit de5b760
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 118 deletions.
13 changes: 5 additions & 8 deletions compiled/facebook-www/JSXDEVRuntime-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,12 +898,6 @@ if (__DEV__) {
}

var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
var RESERVED_PROPS = {
key: true,
ref: true,
__self: true,
__source: true
};
var specialPropKeyWarningShown;
var specialPropRefWarningShown;
var didWarnAboutStringRefs;
Expand Down Expand Up @@ -1134,8 +1128,11 @@ if (__DEV__) {

for (propName in config) {
if (
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS.hasOwnProperty(propName)
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" && // TODO: These will no longer be reserved in the next major
propName !== "ref" &&
propName !== "__self" &&
propName !== "__source"
) {
props[propName] = config[propName];
}
Expand Down
13 changes: 5 additions & 8 deletions compiled/facebook-www/JSXDEVRuntime-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,12 +898,6 @@ if (__DEV__) {
}

var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
var RESERVED_PROPS = {
key: true,
ref: true,
__self: true,
__source: true
};
var specialPropKeyWarningShown;
var specialPropRefWarningShown;
var didWarnAboutStringRefs;
Expand Down Expand Up @@ -1134,8 +1128,11 @@ if (__DEV__) {

for (propName in config) {
if (
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS.hasOwnProperty(propName)
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" && // TODO: These will no longer be reserved in the next major
propName !== "ref" &&
propName !== "__self" &&
propName !== "__source"
) {
props[propName] = 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 @@
0d11563b4a96e0f4f2361cdf7375b12375688163
1beb94133a93a433669a893aef02dd5afec07394
35 changes: 16 additions & 19 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 = "18.3.0-www-classic-12d69e63";
var ReactVersion = "18.3.0-www-classic-715010bd";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -610,12 +610,6 @@ if (__DEV__) {
current: null
};

var RESERVED_PROPS$1 = {
key: true,
ref: true,
__self: true,
__source: true
};
var specialPropKeyWarningShown$1,
specialPropRefWarningShown$1,
didWarnAboutStringRefs$1;
Expand Down Expand Up @@ -839,8 +833,11 @@ if (__DEV__) {

for (propName in config) {
if (
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS$1.hasOwnProperty(propName)
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" && // TODO: These will no longer be reserved in the next major
propName !== "ref" &&
propName !== "__self" &&
propName !== "__source"
) {
props[propName] = config[propName];
}
Expand Down Expand Up @@ -969,8 +966,11 @@ if (__DEV__) {

for (propName in config) {
if (
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS$1.hasOwnProperty(propName)
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" && // TODO: These will no longer be reserved in the next major
propName !== "ref" &&
propName !== "__self" &&
propName !== "__source"
) {
if (config[propName] === undefined && defaultProps !== undefined) {
// Resolve default props
Expand Down Expand Up @@ -1678,12 +1678,6 @@ if (__DEV__) {
}

var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
var RESERVED_PROPS = {
key: true,
ref: true,
__self: true,
__source: true
};
var specialPropKeyWarningShown;
var specialPropRefWarningShown;
var didWarnAboutStringRefs;
Expand Down Expand Up @@ -1914,8 +1908,11 @@ if (__DEV__) {

for (propName in config) {
if (
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS.hasOwnProperty(propName)
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" && // TODO: These will no longer be reserved in the next major
propName !== "ref" &&
propName !== "__self" &&
propName !== "__source"
) {
props[propName] = config[propName];
}
Expand Down
35 changes: 16 additions & 19 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 = "18.3.0-www-modern-3d181aee";
var ReactVersion = "18.3.0-www-modern-20a278f7";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -610,12 +610,6 @@ if (__DEV__) {
current: null
};

var RESERVED_PROPS$1 = {
key: true,
ref: true,
__self: true,
__source: true
};
var specialPropKeyWarningShown$1,
specialPropRefWarningShown$1,
didWarnAboutStringRefs$1;
Expand Down Expand Up @@ -839,8 +833,11 @@ if (__DEV__) {

for (propName in config) {
if (
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS$1.hasOwnProperty(propName)
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" && // TODO: These will no longer be reserved in the next major
propName !== "ref" &&
propName !== "__self" &&
propName !== "__source"
) {
props[propName] = config[propName];
}
Expand Down Expand Up @@ -969,8 +966,11 @@ if (__DEV__) {

for (propName in config) {
if (
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS$1.hasOwnProperty(propName)
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" && // TODO: These will no longer be reserved in the next major
propName !== "ref" &&
propName !== "__self" &&
propName !== "__source"
) {
if (config[propName] === undefined && defaultProps !== undefined) {
// Resolve default props
Expand Down Expand Up @@ -1678,12 +1678,6 @@ if (__DEV__) {
}

var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
var RESERVED_PROPS = {
key: true,
ref: true,
__self: true,
__source: true
};
var specialPropKeyWarningShown;
var specialPropRefWarningShown;
var didWarnAboutStringRefs;
Expand Down Expand Up @@ -1914,8 +1908,11 @@ if (__DEV__) {

for (propName in config) {
if (
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS.hasOwnProperty(propName)
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" && // TODO: These will no longer be reserved in the next major
propName !== "ref" &&
propName !== "__self" &&
propName !== "__source"
) {
props[propName] = config[propName];
}
Expand Down
23 changes: 15 additions & 8 deletions compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ var isArrayImpl = Array.isArray,
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
enableAsyncActions = dynamicFeatureFlags.enableAsyncActions,
hasOwnProperty = Object.prototype.hasOwnProperty,
ReactCurrentOwner$1 = { current: null },
RESERVED_PROPS$1 = { key: !0, ref: !0, __self: !0, __source: !0 };
ReactCurrentOwner$1 = { current: null };
function createElement$1(type, config, children) {
var propName,
props = {},
Expand All @@ -97,7 +96,10 @@ function createElement$1(type, config, children) {
void 0 !== config.key && (key = "" + config.key),
config))
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
"key" !== propName &&
"ref" !== propName &&
"__self" !== propName &&
"__source" !== propName &&
(props[propName] = config[propName]);
var childrenLength = arguments.length - 2;
if (1 === childrenLength) props.children = children;
Expand Down Expand Up @@ -145,8 +147,7 @@ var ReactCurrentDispatcher = { current: null },
ReactCurrentBatchConfig: ReactCurrentBatchConfig,
ReactCurrentOwner: ReactCurrentOwner$1
},
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner,
RESERVED_PROPS = { key: !0, ref: !0, __self: !0, __source: !0 };
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
function jsx$1(type, config, maybeKey) {
var propName,
props = {},
Expand All @@ -157,7 +158,10 @@ function jsx$1(type, config, maybeKey) {
void 0 !== config.ref && (ref = config.ref);
for (propName in config)
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS.hasOwnProperty(propName) &&
"key" !== propName &&
"ref" !== propName &&
"__self" !== propName &&
"__source" !== propName &&
(props[propName] = config[propName]);
if (type && type.defaultProps)
for (propName in ((config = type.defaultProps), config))
Expand Down Expand Up @@ -382,7 +386,10 @@ exports.cloneElement = function (element, config, children) {
var defaultProps = element.type.defaultProps;
for (propName in config)
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
"key" !== propName &&
"ref" !== propName &&
"__self" !== propName &&
"__source" !== propName &&
(props[propName] =
void 0 === config[propName] && void 0 !== defaultProps
? defaultProps[propName]
Expand Down Expand Up @@ -570,4 +577,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-www-classic-b2425be8";
exports.version = "18.3.0-www-classic-a3f180e9";
23 changes: 15 additions & 8 deletions compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ var isArrayImpl = Array.isArray,
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
enableAsyncActions = dynamicFeatureFlags.enableAsyncActions,
hasOwnProperty = Object.prototype.hasOwnProperty,
ReactCurrentOwner$1 = { current: null },
RESERVED_PROPS$1 = { key: !0, ref: !0, __self: !0, __source: !0 };
ReactCurrentOwner$1 = { current: null };
function cloneAndReplaceKey(oldElement, newKey) {
return {
$$typeof: REACT_ELEMENT_TYPE,
Expand All @@ -112,8 +111,7 @@ var ReactCurrentDispatcher = { current: null },
ReactCurrentBatchConfig: ReactCurrentBatchConfig,
ReactCurrentOwner: ReactCurrentOwner$1
},
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner,
RESERVED_PROPS = { key: !0, ref: !0, __self: !0, __source: !0 };
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
function jsx$1(type, config, maybeKey) {
var propName,
props = {},
Expand All @@ -124,7 +122,10 @@ function jsx$1(type, config, maybeKey) {
void 0 !== config.ref && (ref = config.ref);
for (propName in config)
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS.hasOwnProperty(propName) &&
"key" !== propName &&
"ref" !== propName &&
"__self" !== propName &&
"__source" !== propName &&
(props[propName] = config[propName]);
if (type && type.defaultProps)
for (propName in ((config = type.defaultProps), config))
Expand Down Expand Up @@ -349,7 +350,10 @@ exports.cloneElement = function (element, config, children) {
var defaultProps = element.type.defaultProps;
for (propName in config)
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
"key" !== propName &&
"ref" !== propName &&
"__self" !== propName &&
"__source" !== propName &&
(props[propName] =
void 0 === config[propName] && void 0 !== defaultProps
? defaultProps[propName]
Expand Down Expand Up @@ -396,7 +400,10 @@ exports.createElement = function (type, config, children) {
void 0 !== config.key && (key = "" + config.key),
config))
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
"key" !== propName &&
"ref" !== propName &&
"__self" !== propName &&
"__source" !== propName &&
(props[propName] = config[propName]);
var childrenLength = arguments.length - 2;
if (1 === childrenLength) props.children = children;
Expand Down Expand Up @@ -562,4 +569,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-www-modern-1e4811e0";
exports.version = "18.3.0-www-modern-97ff7924";
23 changes: 15 additions & 8 deletions compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ var isArrayImpl = Array.isArray,
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
enableAsyncActions = dynamicFeatureFlags.enableAsyncActions,
hasOwnProperty = Object.prototype.hasOwnProperty,
ReactCurrentOwner$1 = { current: null },
RESERVED_PROPS$1 = { key: !0, ref: !0, __self: !0, __source: !0 };
ReactCurrentOwner$1 = { current: null };
function createElement$1(type, config, children) {
var propName,
props = {},
Expand All @@ -101,7 +100,10 @@ function createElement$1(type, config, children) {
void 0 !== config.key && (key = "" + config.key),
config))
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
"key" !== propName &&
"ref" !== propName &&
"__self" !== propName &&
"__source" !== propName &&
(props[propName] = config[propName]);
var childrenLength = arguments.length - 2;
if (1 === childrenLength) props.children = children;
Expand Down Expand Up @@ -149,8 +151,7 @@ var ReactCurrentDispatcher = { current: null },
ReactCurrentBatchConfig: ReactCurrentBatchConfig,
ReactCurrentOwner: ReactCurrentOwner$1
},
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner,
RESERVED_PROPS = { key: !0, ref: !0, __self: !0, __source: !0 };
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
function jsx$1(type, config, maybeKey) {
var propName,
props = {},
Expand All @@ -161,7 +162,10 @@ function jsx$1(type, config, maybeKey) {
void 0 !== config.ref && (ref = config.ref);
for (propName in config)
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS.hasOwnProperty(propName) &&
"key" !== propName &&
"ref" !== propName &&
"__self" !== propName &&
"__source" !== propName &&
(props[propName] = config[propName]);
if (type && type.defaultProps)
for (propName in ((config = type.defaultProps), config))
Expand Down Expand Up @@ -386,7 +390,10 @@ exports.cloneElement = function (element, config, children) {
var defaultProps = element.type.defaultProps;
for (propName in config)
hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
"key" !== propName &&
"ref" !== propName &&
"__self" !== propName &&
"__source" !== propName &&
(props[propName] =
void 0 === config[propName] && void 0 !== defaultProps
? defaultProps[propName]
Expand Down Expand Up @@ -574,7 +581,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-www-classic-65d179d4";
exports.version = "18.3.0-www-classic-a4e84017";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Loading

0 comments on commit de5b760

Please sign in to comment.