Skip to content

Commit de5b760

Browse files
committed
jsx(): Inline reserved prop checks (#28262)
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)
1 parent e46929f commit de5b760

13 files changed

+138
-118
lines changed

compiled/facebook-www/JSXDEVRuntime-dev.classic.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,6 @@ if (__DEV__) {
898898
}
899899

900900
var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
901-
var RESERVED_PROPS = {
902-
key: true,
903-
ref: true,
904-
__self: true,
905-
__source: true
906-
};
907901
var specialPropKeyWarningShown;
908902
var specialPropRefWarningShown;
909903
var didWarnAboutStringRefs;
@@ -1134,8 +1128,11 @@ if (__DEV__) {
11341128

11351129
for (propName in config) {
11361130
if (
1137-
hasOwnProperty.call(config, propName) &&
1138-
!RESERVED_PROPS.hasOwnProperty(propName)
1131+
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
1132+
propName !== "key" && // TODO: These will no longer be reserved in the next major
1133+
propName !== "ref" &&
1134+
propName !== "__self" &&
1135+
propName !== "__source"
11391136
) {
11401137
props[propName] = config[propName];
11411138
}

compiled/facebook-www/JSXDEVRuntime-dev.modern.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,6 @@ if (__DEV__) {
898898
}
899899

900900
var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
901-
var RESERVED_PROPS = {
902-
key: true,
903-
ref: true,
904-
__self: true,
905-
__source: true
906-
};
907901
var specialPropKeyWarningShown;
908902
var specialPropRefWarningShown;
909903
var didWarnAboutStringRefs;
@@ -1134,8 +1128,11 @@ if (__DEV__) {
11341128

11351129
for (propName in config) {
11361130
if (
1137-
hasOwnProperty.call(config, propName) &&
1138-
!RESERVED_PROPS.hasOwnProperty(propName)
1131+
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
1132+
propName !== "key" && // TODO: These will no longer be reserved in the next major
1133+
propName !== "ref" &&
1134+
propName !== "__self" &&
1135+
propName !== "__source"
11391136
) {
11401137
props[propName] = config[propName];
11411138
}

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0d11563b4a96e0f4f2361cdf7375b12375688163
1+
1beb94133a93a433669a893aef02dd5afec07394

compiled/facebook-www/React-dev.classic.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (__DEV__) {
2424
) {
2525
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2626
}
27-
var ReactVersion = "18.3.0-www-classic-12d69e63";
27+
var ReactVersion = "18.3.0-www-classic-715010bd";
2828

2929
// ATTENTION
3030
// When adding new symbols to this file,
@@ -610,12 +610,6 @@ if (__DEV__) {
610610
current: null
611611
};
612612

613-
var RESERVED_PROPS$1 = {
614-
key: true,
615-
ref: true,
616-
__self: true,
617-
__source: true
618-
};
619613
var specialPropKeyWarningShown$1,
620614
specialPropRefWarningShown$1,
621615
didWarnAboutStringRefs$1;
@@ -839,8 +833,11 @@ if (__DEV__) {
839833

840834
for (propName in config) {
841835
if (
842-
hasOwnProperty.call(config, propName) &&
843-
!RESERVED_PROPS$1.hasOwnProperty(propName)
836+
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
837+
propName !== "key" && // TODO: These will no longer be reserved in the next major
838+
propName !== "ref" &&
839+
propName !== "__self" &&
840+
propName !== "__source"
844841
) {
845842
props[propName] = config[propName];
846843
}
@@ -969,8 +966,11 @@ if (__DEV__) {
969966

970967
for (propName in config) {
971968
if (
972-
hasOwnProperty.call(config, propName) &&
973-
!RESERVED_PROPS$1.hasOwnProperty(propName)
969+
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
970+
propName !== "key" && // TODO: These will no longer be reserved in the next major
971+
propName !== "ref" &&
972+
propName !== "__self" &&
973+
propName !== "__source"
974974
) {
975975
if (config[propName] === undefined && defaultProps !== undefined) {
976976
// Resolve default props
@@ -1678,12 +1678,6 @@ if (__DEV__) {
16781678
}
16791679

16801680
var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
1681-
var RESERVED_PROPS = {
1682-
key: true,
1683-
ref: true,
1684-
__self: true,
1685-
__source: true
1686-
};
16871681
var specialPropKeyWarningShown;
16881682
var specialPropRefWarningShown;
16891683
var didWarnAboutStringRefs;
@@ -1914,8 +1908,11 @@ if (__DEV__) {
19141908

19151909
for (propName in config) {
19161910
if (
1917-
hasOwnProperty.call(config, propName) &&
1918-
!RESERVED_PROPS.hasOwnProperty(propName)
1911+
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
1912+
propName !== "key" && // TODO: These will no longer be reserved in the next major
1913+
propName !== "ref" &&
1914+
propName !== "__self" &&
1915+
propName !== "__source"
19191916
) {
19201917
props[propName] = config[propName];
19211918
}

compiled/facebook-www/React-dev.modern.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (__DEV__) {
2424
) {
2525
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2626
}
27-
var ReactVersion = "18.3.0-www-modern-3d181aee";
27+
var ReactVersion = "18.3.0-www-modern-20a278f7";
2828

2929
// ATTENTION
3030
// When adding new symbols to this file,
@@ -610,12 +610,6 @@ if (__DEV__) {
610610
current: null
611611
};
612612

613-
var RESERVED_PROPS$1 = {
614-
key: true,
615-
ref: true,
616-
__self: true,
617-
__source: true
618-
};
619613
var specialPropKeyWarningShown$1,
620614
specialPropRefWarningShown$1,
621615
didWarnAboutStringRefs$1;
@@ -839,8 +833,11 @@ if (__DEV__) {
839833

840834
for (propName in config) {
841835
if (
842-
hasOwnProperty.call(config, propName) &&
843-
!RESERVED_PROPS$1.hasOwnProperty(propName)
836+
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
837+
propName !== "key" && // TODO: These will no longer be reserved in the next major
838+
propName !== "ref" &&
839+
propName !== "__self" &&
840+
propName !== "__source"
844841
) {
845842
props[propName] = config[propName];
846843
}
@@ -969,8 +966,11 @@ if (__DEV__) {
969966

970967
for (propName in config) {
971968
if (
972-
hasOwnProperty.call(config, propName) &&
973-
!RESERVED_PROPS$1.hasOwnProperty(propName)
969+
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
970+
propName !== "key" && // TODO: These will no longer be reserved in the next major
971+
propName !== "ref" &&
972+
propName !== "__self" &&
973+
propName !== "__source"
974974
) {
975975
if (config[propName] === undefined && defaultProps !== undefined) {
976976
// Resolve default props
@@ -1678,12 +1678,6 @@ if (__DEV__) {
16781678
}
16791679

16801680
var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
1681-
var RESERVED_PROPS = {
1682-
key: true,
1683-
ref: true,
1684-
__self: true,
1685-
__source: true
1686-
};
16871681
var specialPropKeyWarningShown;
16881682
var specialPropRefWarningShown;
16891683
var didWarnAboutStringRefs;
@@ -1914,8 +1908,11 @@ if (__DEV__) {
19141908

19151909
for (propName in config) {
19161910
if (
1917-
hasOwnProperty.call(config, propName) &&
1918-
!RESERVED_PROPS.hasOwnProperty(propName)
1911+
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
1912+
propName !== "key" && // TODO: These will no longer be reserved in the next major
1913+
propName !== "ref" &&
1914+
propName !== "__self" &&
1915+
propName !== "__source"
19191916
) {
19201917
props[propName] = config[propName];
19211918
}

compiled/facebook-www/React-prod.classic.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ var isArrayImpl = Array.isArray,
8585
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
8686
enableAsyncActions = dynamicFeatureFlags.enableAsyncActions,
8787
hasOwnProperty = Object.prototype.hasOwnProperty,
88-
ReactCurrentOwner$1 = { current: null },
89-
RESERVED_PROPS$1 = { key: !0, ref: !0, __self: !0, __source: !0 };
88+
ReactCurrentOwner$1 = { current: null };
9089
function createElement$1(type, config, children) {
9190
var propName,
9291
props = {},
@@ -97,7 +96,10 @@ function createElement$1(type, config, children) {
9796
void 0 !== config.key && (key = "" + config.key),
9897
config))
9998
hasOwnProperty.call(config, propName) &&
100-
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
99+
"key" !== propName &&
100+
"ref" !== propName &&
101+
"__self" !== propName &&
102+
"__source" !== propName &&
101103
(props[propName] = config[propName]);
102104
var childrenLength = arguments.length - 2;
103105
if (1 === childrenLength) props.children = children;
@@ -145,8 +147,7 @@ var ReactCurrentDispatcher = { current: null },
145147
ReactCurrentBatchConfig: ReactCurrentBatchConfig,
146148
ReactCurrentOwner: ReactCurrentOwner$1
147149
},
148-
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner,
149-
RESERVED_PROPS = { key: !0, ref: !0, __self: !0, __source: !0 };
150+
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
150151
function jsx$1(type, config, maybeKey) {
151152
var propName,
152153
props = {},
@@ -157,7 +158,10 @@ function jsx$1(type, config, maybeKey) {
157158
void 0 !== config.ref && (ref = config.ref);
158159
for (propName in config)
159160
hasOwnProperty.call(config, propName) &&
160-
!RESERVED_PROPS.hasOwnProperty(propName) &&
161+
"key" !== propName &&
162+
"ref" !== propName &&
163+
"__self" !== propName &&
164+
"__source" !== propName &&
161165
(props[propName] = config[propName]);
162166
if (type && type.defaultProps)
163167
for (propName in ((config = type.defaultProps), config))
@@ -382,7 +386,10 @@ exports.cloneElement = function (element, config, children) {
382386
var defaultProps = element.type.defaultProps;
383387
for (propName in config)
384388
hasOwnProperty.call(config, propName) &&
385-
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
389+
"key" !== propName &&
390+
"ref" !== propName &&
391+
"__self" !== propName &&
392+
"__source" !== propName &&
386393
(props[propName] =
387394
void 0 === config[propName] && void 0 !== defaultProps
388395
? defaultProps[propName]
@@ -570,4 +577,4 @@ exports.useSyncExternalStore = function (
570577
exports.useTransition = function () {
571578
return ReactCurrentDispatcher.current.useTransition();
572579
};
573-
exports.version = "18.3.0-www-classic-b2425be8";
580+
exports.version = "18.3.0-www-classic-a3f180e9";

compiled/facebook-www/React-prod.modern.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ var isArrayImpl = Array.isArray,
8484
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
8585
enableAsyncActions = dynamicFeatureFlags.enableAsyncActions,
8686
hasOwnProperty = Object.prototype.hasOwnProperty,
87-
ReactCurrentOwner$1 = { current: null },
88-
RESERVED_PROPS$1 = { key: !0, ref: !0, __self: !0, __source: !0 };
87+
ReactCurrentOwner$1 = { current: null };
8988
function cloneAndReplaceKey(oldElement, newKey) {
9089
return {
9190
$$typeof: REACT_ELEMENT_TYPE,
@@ -112,8 +111,7 @@ var ReactCurrentDispatcher = { current: null },
112111
ReactCurrentBatchConfig: ReactCurrentBatchConfig,
113112
ReactCurrentOwner: ReactCurrentOwner$1
114113
},
115-
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner,
116-
RESERVED_PROPS = { key: !0, ref: !0, __self: !0, __source: !0 };
114+
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
117115
function jsx$1(type, config, maybeKey) {
118116
var propName,
119117
props = {},
@@ -124,7 +122,10 @@ function jsx$1(type, config, maybeKey) {
124122
void 0 !== config.ref && (ref = config.ref);
125123
for (propName in config)
126124
hasOwnProperty.call(config, propName) &&
127-
!RESERVED_PROPS.hasOwnProperty(propName) &&
125+
"key" !== propName &&
126+
"ref" !== propName &&
127+
"__self" !== propName &&
128+
"__source" !== propName &&
128129
(props[propName] = config[propName]);
129130
if (type && type.defaultProps)
130131
for (propName in ((config = type.defaultProps), config))
@@ -349,7 +350,10 @@ exports.cloneElement = function (element, config, children) {
349350
var defaultProps = element.type.defaultProps;
350351
for (propName in config)
351352
hasOwnProperty.call(config, propName) &&
352-
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
353+
"key" !== propName &&
354+
"ref" !== propName &&
355+
"__self" !== propName &&
356+
"__source" !== propName &&
353357
(props[propName] =
354358
void 0 === config[propName] && void 0 !== defaultProps
355359
? defaultProps[propName]
@@ -396,7 +400,10 @@ exports.createElement = function (type, config, children) {
396400
void 0 !== config.key && (key = "" + config.key),
397401
config))
398402
hasOwnProperty.call(config, propName) &&
399-
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
403+
"key" !== propName &&
404+
"ref" !== propName &&
405+
"__self" !== propName &&
406+
"__source" !== propName &&
400407
(props[propName] = config[propName]);
401408
var childrenLength = arguments.length - 2;
402409
if (1 === childrenLength) props.children = children;
@@ -562,4 +569,4 @@ exports.useSyncExternalStore = function (
562569
exports.useTransition = function () {
563570
return ReactCurrentDispatcher.current.useTransition();
564571
};
565-
exports.version = "18.3.0-www-modern-1e4811e0";
572+
exports.version = "18.3.0-www-modern-97ff7924";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ var isArrayImpl = Array.isArray,
8989
enableTransitionTracing = dynamicFeatureFlags.enableTransitionTracing,
9090
enableAsyncActions = dynamicFeatureFlags.enableAsyncActions,
9191
hasOwnProperty = Object.prototype.hasOwnProperty,
92-
ReactCurrentOwner$1 = { current: null },
93-
RESERVED_PROPS$1 = { key: !0, ref: !0, __self: !0, __source: !0 };
92+
ReactCurrentOwner$1 = { current: null };
9493
function createElement$1(type, config, children) {
9594
var propName,
9695
props = {},
@@ -101,7 +100,10 @@ function createElement$1(type, config, children) {
101100
void 0 !== config.key && (key = "" + config.key),
102101
config))
103102
hasOwnProperty.call(config, propName) &&
104-
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
103+
"key" !== propName &&
104+
"ref" !== propName &&
105+
"__self" !== propName &&
106+
"__source" !== propName &&
105107
(props[propName] = config[propName]);
106108
var childrenLength = arguments.length - 2;
107109
if (1 === childrenLength) props.children = children;
@@ -149,8 +151,7 @@ var ReactCurrentDispatcher = { current: null },
149151
ReactCurrentBatchConfig: ReactCurrentBatchConfig,
150152
ReactCurrentOwner: ReactCurrentOwner$1
151153
},
152-
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner,
153-
RESERVED_PROPS = { key: !0, ref: !0, __self: !0, __source: !0 };
154+
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
154155
function jsx$1(type, config, maybeKey) {
155156
var propName,
156157
props = {},
@@ -161,7 +162,10 @@ function jsx$1(type, config, maybeKey) {
161162
void 0 !== config.ref && (ref = config.ref);
162163
for (propName in config)
163164
hasOwnProperty.call(config, propName) &&
164-
!RESERVED_PROPS.hasOwnProperty(propName) &&
165+
"key" !== propName &&
166+
"ref" !== propName &&
167+
"__self" !== propName &&
168+
"__source" !== propName &&
165169
(props[propName] = config[propName]);
166170
if (type && type.defaultProps)
167171
for (propName in ((config = type.defaultProps), config))
@@ -386,7 +390,10 @@ exports.cloneElement = function (element, config, children) {
386390
var defaultProps = element.type.defaultProps;
387391
for (propName in config)
388392
hasOwnProperty.call(config, propName) &&
389-
!RESERVED_PROPS$1.hasOwnProperty(propName) &&
393+
"key" !== propName &&
394+
"ref" !== propName &&
395+
"__self" !== propName &&
396+
"__source" !== propName &&
390397
(props[propName] =
391398
void 0 === config[propName] && void 0 !== defaultProps
392399
? defaultProps[propName]
@@ -574,7 +581,7 @@ exports.useSyncExternalStore = function (
574581
exports.useTransition = function () {
575582
return ReactCurrentDispatcher.current.useTransition();
576583
};
577-
exports.version = "18.3.0-www-classic-65d179d4";
584+
exports.version = "18.3.0-www-classic-a4e84017";
578585
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
579586
"function" ===
580587
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)