Skip to content

Commit b966d29

Browse files
rickhanloniifacebook-github-bot
authored andcommitted
Add back deprecated prop-types
Summary: In 2017, React published v15.5 which extracted the built-in `prop types` to a separate package to reflect the fact that not everybody uses them. In 2018, React Native started to remove `PropTypes` from React Native for the same reason. In 0.68 React Native introduced a deprecation warning which notified users that the change was coming, and in 0.69 we removed the PropTypes entirely. The feedback we've received from the community is that there has not been enough time to migrate libraries off of PropTypes. This has resulted in users needing to patch the React Native package `index.js` file directly to add back the PropTypes, instead of migrating off of them. We can empathize with this fix short term (it unblocks the upgrade) but long term this patch will cause users to miss important changes to `index.js`, and add a maintenance cost for users. Part of the reason there was not enough time is that we didn't do a good job surfacing libraries that were using PropTypes. This means, when you got a deprecation warning, it wasn't clear where the source of the usage was (either in your code or in a library). So even if you wanted to migrate, it was difficult to know where to actually make the change. In the next release, we've made it easier to find call sites using deprecated types by [fixing the code frame in errors](react-native-community/cli#1699) reporting in LogBox, and ensuring that [the app doesn't crash without a warning](#34650). This should make it easier to identify exactly where the deprecated usage is, so you can migrate it. To help users get off of the patch, and allow more time to migrate, we're walking back the removal of PropTypes, and keeping it as a deprecation for a couple more versions. We ask that you either migrate off PropTypes to a type system like TypeScript, or migrate to the `deprecated-react-native-prop-types` package. Once we feel more confident that the community has migrated and will not need to patch React Native in order to fix this issue, we'll remove the PropTypes again. **If you have any trouble finding the source of the PropType usage, please file an issue so we can help track it down with you.** Changelog: [General][Changed] - Add back deprecated PropTypes Reviewed By: yungsters Differential Revision: D40725705 fbshipit-source-id: 8ce61be30343827efd6dc89a012eeef0b6676deb
1 parent fa2842d commit b966d29

File tree

8 files changed

+50
-14
lines changed

8 files changed

+50
-14
lines changed

BUCK

+1
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ rn_library(
742742
"//xplat/js:node_modules__abort_19controller",
743743
"//xplat/js:node_modules__anser",
744744
"//xplat/js:node_modules__base64_19js",
745+
"//xplat/js:node_modules__deprecated_19react_19native_19prop_19types",
745746
"//xplat/js:node_modules__event_19target_19shim",
746747
"//xplat/js:node_modules__invariant",
747748
"//xplat/js:node_modules__memoize_19one",

Libraries/Components/TextInput/TextInput.js

+7
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,13 @@ const ExportedForwardRef: React.AbstractComponent<
16501650
);
16511651
});
16521652

1653+
/**
1654+
* Switch to `deprecated-react-native-prop-types` for compatibility with future
1655+
* releases. This is deprecated and will be removed in the future.
1656+
*/
1657+
ExportedForwardRef.propTypes =
1658+
require('deprecated-react-native-prop-types').TextInputPropTypes;
1659+
16531660
// $FlowFixMe[prop-missing]
16541661
ExportedForwardRef.State = {
16551662
currentlyFocusedInput: TextInputState.currentlyFocusedInput,

Libraries/Image/Image.android.js

+6
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ Image.queryCache = queryCache;
325325
* comment and run Flow. */
326326
Image.resolveAssetSource = resolveAssetSource;
327327

328+
/**
329+
* Switch to `deprecated-react-native-prop-types` for compatibility with future
330+
* releases. This is deprecated and will be removed in the future.
331+
*/
332+
Image.propTypes = require('deprecated-react-native-prop-types').ImagePropTypes;
333+
328334
const styles = StyleSheet.create({
329335
base: {
330336
overflow: 'hidden',

Libraries/Image/Image.ios.js

+6
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ Image.queryCache = queryCache;
260260
* delete this comment and run Flow. */
261261
Image.resolveAssetSource = resolveAssetSource;
262262

263+
/**
264+
* Switch to `deprecated-react-native-prop-types` for compatibility with future
265+
* releases. This is deprecated and will be removed in the future.
266+
*/
267+
Image.propTypes = require('deprecated-react-native-prop-types').ImagePropTypes;
268+
263269
const styles = StyleSheet.create({
264270
base: {
265271
overflow: 'hidden',

Libraries/Text/Text.js

+6
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ const Text: React.AbstractComponent<
270270

271271
Text.displayName = 'Text';
272272

273+
/**
274+
* Switch to `deprecated-react-native-prop-types` for compatibility with future
275+
* releases. This is deprecated and will be removed in the future.
276+
*/
277+
Text.propTypes = require('deprecated-react-native-prop-types').TextPropTypes;
278+
273279
/**
274280
* Returns false until the first time `newValue` is true, after which this will
275281
* always return true. This is necessary to lazily initialize `Pressability` so

index.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -433,44 +433,44 @@ module.exports = {
433433
},
434434
// Deprecated Prop Types
435435
get ColorPropType(): $FlowFixMe {
436-
invariant(
437-
false,
438-
'ColorPropType has been removed from React Native, along with all ' +
436+
console.error(
437+
'ColorPropType will be removed from React Native, along with all ' +
439438
'other PropTypes. We recommend that you migrate away from PropTypes ' +
440439
'and switch to a type system like TypeScript. If you need to ' +
441440
'continue using ColorPropType, migrate to the ' +
442441
"'deprecated-react-native-prop-types' package.",
443442
);
443+
return require('deprecated-react-native-prop-types').ColorPropType;
444444
},
445445
get EdgeInsetsPropType(): $FlowFixMe {
446-
invariant(
447-
false,
448-
'EdgeInsetsPropType has been removed from React Native, along with all ' +
446+
console.error(
447+
'EdgeInsetsPropType will be removed from React Native, along with all ' +
449448
'other PropTypes. We recommend that you migrate away from PropTypes ' +
450449
'and switch to a type system like TypeScript. If you need to ' +
451450
'continue using EdgeInsetsPropType, migrate to the ' +
452451
"'deprecated-react-native-prop-types' package.",
453452
);
453+
return require('deprecated-react-native-prop-types').EdgeInsetsPropType;
454454
},
455455
get PointPropType(): $FlowFixMe {
456-
invariant(
457-
false,
458-
'PointPropType has been removed from React Native, along with all ' +
456+
console.error(
457+
'PointPropType will be removed from React Native, along with all ' +
459458
'other PropTypes. We recommend that you migrate away from PropTypes ' +
460459
'and switch to a type system like TypeScript. If you need to ' +
461460
'continue using PointPropType, migrate to the ' +
462461
"'deprecated-react-native-prop-types' package.",
463462
);
463+
return require('deprecated-react-native-prop-types').PointPropType;
464464
},
465465
get ViewPropTypes(): $FlowFixMe {
466-
invariant(
467-
false,
468-
'ViewPropTypes has been removed from React Native, along with all ' +
466+
console.error(
467+
'ViewPropTypes will be removed from React Native, along with all ' +
469468
'other PropTypes. We recommend that you migrate away from PropTypes ' +
470469
'and switch to a type system like TypeScript. If you need to ' +
471470
'continue using ViewPropTypes, migrate to the ' +
472471
"'deprecated-react-native-prop-types' package.",
473472
);
473+
return require('deprecated-react-native-prop-types').ViewPropTypes;
474474
},
475475
};
476476

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
"abort-controller": "^3.0.0",
119119
"anser": "^1.4.9",
120120
"base64-js": "^1.1.2",
121+
"deprecated-react-native-prop-types": "^2.3.0",
121122
"event-target-shim": "^5.0.1",
122123
"invariant": "^2.2.4",
123124
"jest-environment-node": "^29.2.1",

yarn.lock

+11-2
Original file line numberDiff line numberDiff line change
@@ -4145,6 +4145,15 @@ depd@~1.1.2:
41454145
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9"
41464146
integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=
41474147

4148+
deprecated-react-native-prop-types@^2.3.0:
4149+
version "2.3.0"
4150+
resolved "https://registry.yarnpkg.com/deprecated-react-native-prop-types/-/deprecated-react-native-prop-types-2.3.0.tgz#c10c6ee75ff2b6de94bb127f142b814e6e08d9ab"
4151+
integrity sha512-pWD0voFtNYxrVqvBMYf5gq3NA2GCpfodS1yNynTPc93AYA/KEMGeWDqqeUB6R2Z9ZofVhks2aeJXiuQqKNpesA==
4152+
dependencies:
4153+
"@react-native/normalize-color" "*"
4154+
invariant "*"
4155+
prop-types "*"
4156+
41484157
deprecation@^2.0.0, deprecation@^2.3.1:
41494158
version "2.3.1"
41504159
resolved "https://registry.yarnpkg.com/deprecation/-/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919"
@@ -5548,7 +5557,7 @@ interpret@^1.0.0:
55485557
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.1.0.tgz#7ed1b1410c6a0e0f78cf95d3b8440c63f78b8614"
55495558
integrity sha1-ftGxQQxqDg94z5XTuEQMY/eLhhQ=
55505559

5551-
invariant@^2.2.4:
5560+
invariant@*, invariant@^2.2.4:
55525561
version "2.2.4"
55535562
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
55545563
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
@@ -7848,7 +7857,7 @@ prompts@^2.0.1, prompts@^2.4.0:
78487857
kleur "^3.0.3"
78497858
sisteransi "^1.0.5"
78507859

7851-
prop-types@^15.8.1:
7860+
prop-types@*, prop-types@^15.8.1:
78527861
version "15.8.1"
78537862
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
78547863
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==

0 commit comments

Comments
 (0)