Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4c720b

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 [48b4ecc](48b4ecc)
1 parent 2f685cb commit a4c720b

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c0b5d435986e7d9b52a529b73b9317a7e5772172
1+
48b4ecc9012638ed51b275aad24b2086b8215e32

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,6 @@ if (__DEV__) {
834834
return new Set(_data);
835835
}
836836

837-
case "B": {
838-
return undefined;
839-
}
840-
841837
case "I": {
842838
// $Infinity
843839
return Infinity;
@@ -890,9 +886,9 @@ if (__DEV__) {
890886

891887
default: {
892888
// We assume that anything else is a reference ID.
893-
var _id7 = parseInt(value.slice(1), 16);
889+
var _id6 = parseInt(value.slice(1), 16);
894890

895-
var _chunk2 = getChunk(response, _id7);
891+
var _chunk2 = getChunk(response, _id6);
896892

897893
switch (_chunk2.status) {
898894
case RESOLVED_MODEL:

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@ function parseModelString(response, parentObject, key, value) {
294294
(response = getOutlinedModel(response, parentObject)),
295295
new Set(response)
296296
);
297-
case "B":
298-
return;
299297
case "I":
300298
return Infinity;
301299
case "-":

0 commit comments

Comments
 (0)