Skip to content

Commit 47691a3

Browse files
committed
Remove defaultProps support (except for classes) (#28733)
This removes defaultProps support for all component types except for classes. We've chosen to continue supporting defaultProps for classes because lots of older code relies on it, and unlike function components, (which can use default params), there's no straightforward alternative. By implication, it also removes support for setting defaultProps on `React.lazy` wrapper. So this will not work: ```js const MyClassComponent = React.lazy(() => import('./MyClassComponent')); // MyClassComponent is not actually a class; it's a lazy wrapper. So // defaultProps does not work. MyClassComponent.defaultProps = { foo: 'bar' }; ``` However, if you set the default props on the class itself, then it's fine. For classes, this change also moves where defaultProps are resolved. Previously, defaultProps were resolved by the JSX runtime. This change is only observable if you introspect a JSX element, which is relatively rare but does happen. In other words, previously `<ClassWithDefaultProp />.props.aDefaultProp` would resolve to the default prop value, but now it does not. DiffTrain build for commit 48b4ecc.
1 parent bd1135f commit 47691a3

17 files changed

+3509
-3584
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js

Lines changed: 488 additions & 408 deletions
Large diffs are not rendered by default.

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js

Lines changed: 254 additions & 168 deletions
Large diffs are not rendered by default.

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js

Lines changed: 209 additions & 145 deletions
Large diffs are not rendered by default.

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/JSXDEVRuntime-dev.js

Lines changed: 89 additions & 322 deletions
Large diffs are not rendered by default.

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/JSXRuntime-dev.js

Lines changed: 89 additions & 322 deletions
Large diffs are not rendered by default.

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/JSXRuntime-prod.js

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,78 +7,44 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<b4bf34965feaa60392dd96103e5ba9fc>>
10+
* @generated SignedSource<<26fbc8eee6902991682d526f8537439c>>
1111
*/
1212

1313
"use strict";
1414
var dynamicFlagsUntyped = require("ReactNativeInternalFeatureFlags"),
1515
React = require("react"),
1616
REACT_ELEMENT_TYPE = Symbol.for("react.element"),
17-
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
18-
function formatProdErrorMessage(code) {
19-
var url = "https://react.dev/errors/" + code;
20-
if (1 < arguments.length) {
21-
url += "?args[]=" + encodeURIComponent(arguments[1]);
22-
for (var i = 2; i < arguments.length; i++)
23-
url += "&args[]=" + encodeURIComponent(arguments[i]);
24-
}
25-
return (
26-
"Minified React error #" +
27-
code +
28-
"; visit " +
29-
url +
30-
" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."
31-
);
32-
}
33-
var disableDefaultPropsExceptForClasses =
17+
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
18+
disableDefaultPropsExceptForClasses =
3419
dynamicFlagsUntyped.disableDefaultPropsExceptForClasses,
35-
ReactSharedInternals =
36-
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
20+
hasOwnProperty = Object.prototype.hasOwnProperty,
21+
ReactCurrentOwner =
22+
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner;
3723
function jsxProd(type, config, maybeKey) {
38-
var key = null,
24+
var propName,
25+
props = {},
26+
key = null,
3927
ref = null;
4028
void 0 !== maybeKey && (key = "" + maybeKey);
4129
void 0 !== config.key && (key = "" + config.key);
42-
if (void 0 !== config.ref)
43-
a: {
44-
if (((ref = config.ref), "string" !== typeof ref))
45-
if ("number" === typeof ref || "boolean" === typeof ref) ref = "" + ref;
46-
else break a;
47-
ref = stringRefAsCallbackRef.bind(
48-
null,
49-
ref,
50-
type,
51-
ReactSharedInternals.owner
52-
);
53-
}
54-
maybeKey = {};
55-
for (var propName in config)
56-
"key" !== propName &&
30+
void 0 !== config.ref && (ref = config.ref);
31+
for (propName in config)
32+
hasOwnProperty.call(config, propName) &&
33+
"key" !== propName &&
5734
"ref" !== propName &&
58-
(maybeKey[propName] = config[propName]);
59-
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps) {
60-
config = type.defaultProps;
61-
for (var propName$0 in config)
62-
void 0 === maybeKey[propName$0] &&
63-
(maybeKey[propName$0] = config[propName$0]);
64-
}
35+
(props[propName] = config[propName]);
36+
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps)
37+
for (propName in ((config = type.defaultProps), config))
38+
void 0 === props[propName] && (props[propName] = config[propName]);
6539
return {
6640
$$typeof: REACT_ELEMENT_TYPE,
6741
type: type,
6842
key: key,
6943
ref: ref,
70-
props: maybeKey,
71-
_owner: ReactSharedInternals.owner
44+
props: props,
45+
_owner: ReactCurrentOwner.current
7246
};
7347
}
74-
function stringRefAsCallbackRef(stringRef, type, owner, value) {
75-
if (!owner) throw Error(formatProdErrorMessage(290, stringRef));
76-
if (1 !== owner.tag) throw Error(formatProdErrorMessage(309));
77-
type = owner.stateNode;
78-
if (!type) throw Error(formatProdErrorMessage(147, stringRef));
79-
type = type.refs;
80-
null === value ? delete type[stringRef] : (type[stringRef] = value);
81-
}
8248
exports.Fragment = REACT_FRAGMENT_TYPE;
8349
exports.jsx = jsxProd;
8450
exports.jsxs = jsxProd;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/JSXRuntime-profiling.js

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,78 +7,44 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<b4bf34965feaa60392dd96103e5ba9fc>>
10+
* @generated SignedSource<<26fbc8eee6902991682d526f8537439c>>
1111
*/
1212

1313
"use strict";
1414
var dynamicFlagsUntyped = require("ReactNativeInternalFeatureFlags"),
1515
React = require("react"),
1616
REACT_ELEMENT_TYPE = Symbol.for("react.element"),
17-
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
18-
function formatProdErrorMessage(code) {
19-
var url = "https://react.dev/errors/" + code;
20-
if (1 < arguments.length) {
21-
url += "?args[]=" + encodeURIComponent(arguments[1]);
22-
for (var i = 2; i < arguments.length; i++)
23-
url += "&args[]=" + encodeURIComponent(arguments[i]);
24-
}
25-
return (
26-
"Minified React error #" +
27-
code +
28-
"; visit " +
29-
url +
30-
" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."
31-
);
32-
}
33-
var disableDefaultPropsExceptForClasses =
17+
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
18+
disableDefaultPropsExceptForClasses =
3419
dynamicFlagsUntyped.disableDefaultPropsExceptForClasses,
35-
ReactSharedInternals =
36-
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
20+
hasOwnProperty = Object.prototype.hasOwnProperty,
21+
ReactCurrentOwner =
22+
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner;
3723
function jsxProd(type, config, maybeKey) {
38-
var key = null,
24+
var propName,
25+
props = {},
26+
key = null,
3927
ref = null;
4028
void 0 !== maybeKey && (key = "" + maybeKey);
4129
void 0 !== config.key && (key = "" + config.key);
42-
if (void 0 !== config.ref)
43-
a: {
44-
if (((ref = config.ref), "string" !== typeof ref))
45-
if ("number" === typeof ref || "boolean" === typeof ref) ref = "" + ref;
46-
else break a;
47-
ref = stringRefAsCallbackRef.bind(
48-
null,
49-
ref,
50-
type,
51-
ReactSharedInternals.owner
52-
);
53-
}
54-
maybeKey = {};
55-
for (var propName in config)
56-
"key" !== propName &&
30+
void 0 !== config.ref && (ref = config.ref);
31+
for (propName in config)
32+
hasOwnProperty.call(config, propName) &&
33+
"key" !== propName &&
5734
"ref" !== propName &&
58-
(maybeKey[propName] = config[propName]);
59-
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps) {
60-
config = type.defaultProps;
61-
for (var propName$0 in config)
62-
void 0 === maybeKey[propName$0] &&
63-
(maybeKey[propName$0] = config[propName$0]);
64-
}
35+
(props[propName] = config[propName]);
36+
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps)
37+
for (propName in ((config = type.defaultProps), config))
38+
void 0 === props[propName] && (props[propName] = config[propName]);
6539
return {
6640
$$typeof: REACT_ELEMENT_TYPE,
6741
type: type,
6842
key: key,
6943
ref: ref,
70-
props: maybeKey,
71-
_owner: ReactSharedInternals.owner
44+
props: props,
45+
_owner: ReactCurrentOwner.current
7246
};
7347
}
74-
function stringRefAsCallbackRef(stringRef, type, owner, value) {
75-
if (!owner) throw Error(formatProdErrorMessage(290, stringRef));
76-
if (1 !== owner.tag) throw Error(formatProdErrorMessage(309));
77-
type = owner.stateNode;
78-
if (!type) throw Error(formatProdErrorMessage(147, stringRef));
79-
type = type.refs;
80-
null === value ? delete type[stringRef] : (type[stringRef] = value);
81-
}
8248
exports.Fragment = REACT_FRAGMENT_TYPE;
8349
exports.jsx = jsxProd;
8450
exports.jsxs = jsxProd;

0 commit comments

Comments
 (0)