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 commit 1beb941.
  • Loading branch information
acdlite committed Feb 7, 2024
1 parent ef80012 commit 571a247
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25725,7 +25725,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "18.3.0-canary-0d11563b4-20240206";
var ReactVersion = "18.3.0-canary-1beb94133-20240206";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9157,7 +9157,7 @@ var devToolsConfig$jscomp$inline_1012 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-0d11563b4-20240206",
version: "18.3.0-canary-1beb94133-20240206",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1190 = {
Expand Down Expand Up @@ -9188,7 +9188,7 @@ var internals$jscomp$inline_1190 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-0d11563b4-20240206"
reconcilerVersion: "18.3.0-canary-1beb94133-20240206"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1191 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9585,7 +9585,7 @@ var devToolsConfig$jscomp$inline_1054 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-0d11563b4-20240206",
version: "18.3.0-canary-1beb94133-20240206",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1231 = {
Expand Down Expand Up @@ -9616,7 +9616,7 @@ var internals$jscomp$inline_1231 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-0d11563b4-20240206"
reconcilerVersion: "18.3.0-canary-1beb94133-20240206"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1232 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<3b95e8aa7ce2e31fd615f920b4402e91>>
* @generated SignedSource<<b24db7b649efc008c0c89e90dba4877a>>
*/

"use strict";
Expand Down Expand Up @@ -563,12 +563,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 @@ -799,8 +793,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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<8fbe3bc0848b0909865f9804f5adcef7>>
* @generated SignedSource<<4e6cfb0b86828f5be0c6c8e34f4fdb7a>>
*/

"use strict";
Expand Down Expand Up @@ -563,12 +563,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 @@ -799,8 +793,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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<82444ded84168f50c5e2d5115e52dac9>>
* @generated SignedSource<<d95535f2595d28064d67106ad7fa3c58>>
*/

"use strict";
Expand All @@ -16,8 +16,7 @@ var React = require("react"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
hasOwnProperty = Object.prototype.hasOwnProperty,
ReactCurrentOwner =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,
RESERVED_PROPS = { key: !0, ref: !0, __self: !0, __source: !0 };
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner;
function jsx$1(type, config, maybeKey) {
var propName,
props = {},
Expand All @@ -28,7 +27,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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<82444ded84168f50c5e2d5115e52dac9>>
* @generated SignedSource<<d95535f2595d28064d67106ad7fa3c58>>
*/

"use strict";
Expand All @@ -16,8 +16,7 @@ var React = require("react"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
hasOwnProperty = Object.prototype.hasOwnProperty,
ReactCurrentOwner =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,
RESERVED_PROPS = { key: !0, ref: !0, __self: !0, __source: !0 };
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner;
function jsx$1(type, config, maybeKey) {
var propName,
props = {},
Expand All @@ -28,7 +27,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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<8d63d863a541aceb06d589df679b4dc2>>
* @generated SignedSource<<593daac7ac70a57cfd731bbfdac659fc>>
*/

"use strict";
Expand All @@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "18.3.0-canary-0d11563b4-20240206";
var ReactVersion = "18.3.0-canary-1beb94133-20240206";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -679,12 +679,6 @@ if (__DEV__) {
// $FlowFixMe[method-unbinding]
var hasOwnProperty = Object.prototype.hasOwnProperty;

var RESERVED_PROPS$1 = {
key: true,
ref: true,
__self: true,
__source: true
};
var specialPropKeyWarningShown$1,
specialPropRefWarningShown$1,
didWarnAboutStringRefs$1;
Expand Down Expand Up @@ -908,8 +902,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 @@ -1038,8 +1035,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 @@ -1352,12 +1352,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 @@ -1588,8 +1582,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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<488ba8e30fbf06899d70dafff11452dc>>
* @generated SignedSource<<ba8018b7d9a5dbed3051133347c5987d>>
*/

"use strict";
Expand Down Expand Up @@ -82,8 +82,7 @@ assign(pureComponentPrototype, Component.prototype);
pureComponentPrototype.isPureReactComponent = !0;
var isArrayImpl = Array.isArray,
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 @@ -94,7 +93,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 @@ -142,8 +144,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 @@ -154,7 +155,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 @@ -377,7 +381,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 @@ -543,4 +550,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-0d11563b4-20240206";
exports.version = "18.3.0-canary-1beb94133-20240206";
Loading

0 comments on commit 571a247

Please sign in to comment.