Skip to content

Commit 81206cb

Browse files
committed
Remove JSX propTypes validation (#28328)
This removes the remaining `propTypes` validation calls, making declaring `propTypes` a no-op. In other words, React itself will no longer validate the `propTypes` that you declare on your components. In general, our recommendation is to use static type checking (e.g. TypeScript). If you'd like to still run propTypes checks, you can do so manually, same as you'd do outside React: ```js import checkPropTypes from 'prop-types/checkPropTypes'; function Button(props) { checkPropTypes(Button.propTypes, prop, 'prop', Button.name) // ... } ``` This could be automated as a Babel plugin if you want to keep these checks implicit. (We will not be providing such a plugin, but someone in community might be interested in building or maintaining one.) DiffTrain build for commit 353ecd0.
1 parent c825387 commit 81206cb

File tree

9 files changed

+18
-537
lines changed

9 files changed

+18
-537
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -25696,7 +25696,7 @@ if (__DEV__) {
2569625696
return root;
2569725697
}
2569825698

25699-
var ReactVersion = "18.3.0-canary-4ea424e63-20240220";
25699+
var ReactVersion = "18.3.0-canary-353ecd051-20240221";
2570025700

2570125701
// Might add PROFILE later.
2570225702

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -9176,7 +9176,7 @@ var devToolsConfig$jscomp$inline_1014 = {
91769176
throw Error("TestRenderer does not support findFiberByHostInstance()");
91779177
},
91789178
bundleType: 0,
9179-
version: "18.3.0-canary-4ea424e63-20240220",
9179+
version: "18.3.0-canary-353ecd051-20240221",
91809180
rendererPackageName: "react-test-renderer"
91819181
};
91829182
var internals$jscomp$inline_1195 = {
@@ -9207,7 +9207,7 @@ var internals$jscomp$inline_1195 = {
92079207
scheduleRoot: null,
92089208
setRefreshHandler: null,
92099209
getCurrentFiber: null,
9210-
reconcilerVersion: "18.3.0-canary-4ea424e63-20240220"
9210+
reconcilerVersion: "18.3.0-canary-353ecd051-20240221"
92119211
};
92129212
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
92139213
var hook$jscomp$inline_1196 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -9604,7 +9604,7 @@ var devToolsConfig$jscomp$inline_1056 = {
96049604
throw Error("TestRenderer does not support findFiberByHostInstance()");
96059605
},
96069606
bundleType: 0,
9607-
version: "18.3.0-canary-4ea424e63-20240220",
9607+
version: "18.3.0-canary-353ecd051-20240221",
96089608
rendererPackageName: "react-test-renderer"
96099609
};
96109610
var internals$jscomp$inline_1236 = {
@@ -9635,7 +9635,7 @@ var internals$jscomp$inline_1236 = {
96359635
scheduleRoot: null,
96369636
setRefreshHandler: null,
96379637
getCurrentFiber: null,
9638-
reconcilerVersion: "18.3.0-canary-4ea424e63-20240220"
9638+
reconcilerVersion: "18.3.0-canary-353ecd051-20240221"
96399639
};
96409640
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
96419641
var hook$jscomp$inline_1237 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

+1-173
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<20a889fc4c8eaee85875c7091bc5ea65>>
10+
* @generated SignedSource<<a9c49bc89f61d32aa1bc5a10d3664a01>>
1111
*/
1212

1313
"use strict";
@@ -443,111 +443,6 @@ if (__DEV__) {
443443
return "";
444444
}
445445

446-
var loggedTypeFailures = {};
447-
var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
448-
449-
function setCurrentlyValidatingElement$1(element) {
450-
{
451-
if (element) {
452-
var owner = element._owner;
453-
var stack = describeUnknownElementTypeFrameInDEV(
454-
element.type,
455-
owner ? owner.type : null
456-
);
457-
ReactDebugCurrentFrame$1.setExtraStackFrame(stack);
458-
} else {
459-
ReactDebugCurrentFrame$1.setExtraStackFrame(null);
460-
}
461-
}
462-
}
463-
464-
function checkPropTypes(
465-
typeSpecs,
466-
values,
467-
location,
468-
componentName,
469-
element
470-
) {
471-
{
472-
// $FlowFixMe[incompatible-use] This is okay but Flow doesn't know it.
473-
var has = Function.call.bind(hasOwnProperty);
474-
475-
for (var typeSpecName in typeSpecs) {
476-
if (has(typeSpecs, typeSpecName)) {
477-
var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
478-
// fail the render phase where it didn't fail before. So we log it.
479-
// After these have been cleaned up, we'll let them throw.
480-
481-
try {
482-
// This is intentionally an invariant that gets caught. It's the same
483-
// behavior as without this statement except with a better message.
484-
if (typeof typeSpecs[typeSpecName] !== "function") {
485-
// eslint-disable-next-line react-internal/prod-error-codes
486-
var err = Error(
487-
(componentName || "React class") +
488-
": " +
489-
location +
490-
" type `" +
491-
typeSpecName +
492-
"` is invalid; " +
493-
"it must be a function, usually from the `prop-types` package, but received `" +
494-
typeof typeSpecs[typeSpecName] +
495-
"`." +
496-
"This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."
497-
);
498-
err.name = "Invariant Violation";
499-
throw err;
500-
}
501-
502-
error$1 = typeSpecs[typeSpecName](
503-
values,
504-
typeSpecName,
505-
componentName,
506-
location,
507-
null,
508-
"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"
509-
);
510-
} catch (ex) {
511-
error$1 = ex;
512-
}
513-
514-
if (error$1 && !(error$1 instanceof Error)) {
515-
setCurrentlyValidatingElement$1(element);
516-
517-
error(
518-
"%s: type specification of %s" +
519-
" `%s` is invalid; the type checker " +
520-
"function must return `null` or an `Error` but returned a %s. " +
521-
"You may have forgotten to pass an argument to the type checker " +
522-
"creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and " +
523-
"shape all require an argument).",
524-
componentName || "React class",
525-
location,
526-
typeSpecName,
527-
typeof error$1
528-
);
529-
530-
setCurrentlyValidatingElement$1(null);
531-
}
532-
533-
if (
534-
error$1 instanceof Error &&
535-
!(error$1.message in loggedTypeFailures)
536-
) {
537-
// Only monitor this failure once because there tends to be a lot of the
538-
// same error.
539-
loggedTypeFailures[error$1.message] = true;
540-
setCurrentlyValidatingElement$1(element);
541-
542-
error("Failed %s type: %s", location, error$1.message);
543-
544-
setCurrentlyValidatingElement$1(null);
545-
}
546-
}
547-
}
548-
}
549-
}
550-
551446
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
552447
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
553448
var REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference");
@@ -950,8 +845,6 @@ if (__DEV__) {
950845

951846
if (type === REACT_FRAGMENT_TYPE) {
952847
validateFragmentProps(element);
953-
} else {
954-
validatePropTypes(element);
955848
}
956849

957850
return element;
@@ -1178,71 +1071,6 @@ if (__DEV__) {
11781071
}
11791072
}
11801073

1181-
var propTypesMisspellWarningShown = false;
1182-
/**
1183-
* Given an element, validate that its props follow the propTypes definition,
1184-
* provided by the type.
1185-
*
1186-
* @param {ReactElement} element
1187-
*/
1188-
1189-
function validatePropTypes(element) {
1190-
{
1191-
var type = element.type;
1192-
1193-
if (type === null || type === undefined || typeof type === "string") {
1194-
return;
1195-
}
1196-
1197-
if (type.$$typeof === REACT_CLIENT_REFERENCE) {
1198-
return;
1199-
}
1200-
1201-
var propTypes;
1202-
1203-
if (typeof type === "function") {
1204-
propTypes = type.propTypes;
1205-
} else if (
1206-
typeof type === "object" &&
1207-
(type.$$typeof === REACT_FORWARD_REF_TYPE || // Note: Memo only checks outer props here.
1208-
// Inner props are checked in the reconciler.
1209-
type.$$typeof === REACT_MEMO_TYPE)
1210-
) {
1211-
propTypes = type.propTypes;
1212-
} else {
1213-
return;
1214-
}
1215-
1216-
if (propTypes) {
1217-
// Intentionally inside to avoid triggering lazy initializers:
1218-
var name = getComponentNameFromType(type);
1219-
checkPropTypes(propTypes, element.props, "prop", name, element);
1220-
} else if (
1221-
type.PropTypes !== undefined &&
1222-
!propTypesMisspellWarningShown
1223-
) {
1224-
propTypesMisspellWarningShown = true; // Intentionally inside to avoid triggering lazy initializers:
1225-
1226-
var _name = getComponentNameFromType(type);
1227-
1228-
error(
1229-
"Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",
1230-
_name || "Unknown"
1231-
);
1232-
}
1233-
1234-
if (
1235-
typeof type.getDefaultProps === "function" &&
1236-
!type.getDefaultProps.isReactClassApproved
1237-
) {
1238-
error(
1239-
"getDefaultProps is only used on classic React.createClass " +
1240-
"definitions. Use a static property named `defaultProps` instead."
1241-
);
1242-
}
1243-
}
1244-
}
1245-
12461074
var jsxDEV = jsxDEV$1;
12471075

12481076
exports.Fragment = REACT_FRAGMENT_TYPE;

0 commit comments

Comments
 (0)