From a4c720b9e47fdc0033de246dff358141d87e895a Mon Sep 17 00:00:00 2001 From: kassens Date: Thu, 11 Apr 2024 21:29:14 +0000 Subject: [PATCH] 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 `.props.aDefaultProp` would resolve to the default prop value, but now it does not. DiffTrain build for [48b4ecc9012638ed51b275aad24b2086b8215e32](https://github.com/facebook/react/commit/48b4ecc9012638ed51b275aad24b2086b8215e32) --- compiled/facebook-www/REVISION | 2 +- compiled/facebook-www/ReactFlightDOMClient-dev.modern.js | 8 ++------ compiled/facebook-www/ReactFlightDOMClient-prod.modern.js | 2 -- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/compiled/facebook-www/REVISION b/compiled/facebook-www/REVISION index e877cd7b66..efcac2c6f9 100644 --- a/compiled/facebook-www/REVISION +++ b/compiled/facebook-www/REVISION @@ -1 +1 @@ -c0b5d435986e7d9b52a529b73b9317a7e5772172 +48b4ecc9012638ed51b275aad24b2086b8215e32 diff --git a/compiled/facebook-www/ReactFlightDOMClient-dev.modern.js b/compiled/facebook-www/ReactFlightDOMClient-dev.modern.js index 16b6700c2e..f4505884bf 100644 --- a/compiled/facebook-www/ReactFlightDOMClient-dev.modern.js +++ b/compiled/facebook-www/ReactFlightDOMClient-dev.modern.js @@ -834,10 +834,6 @@ if (__DEV__) { return new Set(_data); } - case "B": { - return undefined; - } - case "I": { // $Infinity return Infinity; @@ -890,9 +886,9 @@ if (__DEV__) { default: { // We assume that anything else is a reference ID. - var _id7 = parseInt(value.slice(1), 16); + var _id6 = parseInt(value.slice(1), 16); - var _chunk2 = getChunk(response, _id7); + var _chunk2 = getChunk(response, _id6); switch (_chunk2.status) { case RESOLVED_MODEL: diff --git a/compiled/facebook-www/ReactFlightDOMClient-prod.modern.js b/compiled/facebook-www/ReactFlightDOMClient-prod.modern.js index 0bd061730a..89e779f493 100644 --- a/compiled/facebook-www/ReactFlightDOMClient-prod.modern.js +++ b/compiled/facebook-www/ReactFlightDOMClient-prod.modern.js @@ -294,8 +294,6 @@ function parseModelString(response, parentObject, key, value) { (response = getOutlinedModel(response, parentObject)), new Set(response) ); - case "B": - return; case "I": return Infinity; case "-":