Skip to content

Commit b4437a8

Browse files
committed
Remove non-JSX propTypes checks
1 parent adadb81 commit b4437a8

File tree

6 files changed

+56
-375
lines changed

6 files changed

+56
-375
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

-135
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import type {TracingMarkerInstance} from './ReactFiberTracingMarkerComponent';
4040
import type {TransitionStatus} from './ReactFiberConfig';
4141
import type {Hook} from './ReactFiberHooks';
4242

43-
import checkPropTypes from 'shared/checkPropTypes';
4443
import {
4544
markComponentRenderStarted,
4645
markComponentRenderStopped,
@@ -401,23 +400,6 @@ function updateForwardRef(
401400
// TODO: current can be non-null here even if the component
402401
// hasn't yet mounted. This happens after the first render suspends.
403402
// We'll need to figure out if this is fine or can cause issues.
404-
405-
if (__DEV__) {
406-
if (workInProgress.type !== workInProgress.elementType) {
407-
// Lazy component props can't be validated in createElement
408-
// because they're only guaranteed to be resolved here.
409-
const innerPropTypes = Component.propTypes;
410-
if (innerPropTypes) {
411-
checkPropTypes(
412-
innerPropTypes,
413-
nextProps, // Resolved props
414-
'prop',
415-
getComponentNameFromType(Component),
416-
);
417-
}
418-
}
419-
}
420-
421403
const render = Component.render;
422404
const ref = workInProgress.ref;
423405

@@ -507,17 +489,6 @@ function updateMemoComponent(
507489
);
508490
}
509491
if (__DEV__) {
510-
const innerPropTypes = type.propTypes;
511-
if (innerPropTypes) {
512-
// Inner memo component props aren't currently validated in createElement.
513-
// We could move it there, but we'd still need this for lazy code path.
514-
checkPropTypes(
515-
innerPropTypes,
516-
nextProps, // Resolved props
517-
'prop',
518-
getComponentNameFromType(type),
519-
);
520-
}
521492
if (Component.defaultProps !== undefined) {
522493
const componentName = getComponentNameFromType(type) || 'Unknown';
523494
if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) {
@@ -543,20 +514,6 @@ function updateMemoComponent(
543514
workInProgress.child = child;
544515
return child;
545516
}
546-
if (__DEV__) {
547-
const type = Component.type;
548-
const innerPropTypes = type.propTypes;
549-
if (innerPropTypes) {
550-
// Inner memo component props aren't currently validated in createElement.
551-
// We could move it there, but we'd still need this for lazy code path.
552-
checkPropTypes(
553-
innerPropTypes,
554-
nextProps, // Resolved props
555-
'prop',
556-
getComponentNameFromType(type),
557-
);
558-
}
559-
}
560517
const currentChild = ((current.child: any): Fiber); // This is always exactly one child
561518
const hasScheduledUpdateOrContext = checkScheduledUpdateOrContext(
562519
current,
@@ -592,37 +549,6 @@ function updateSimpleMemoComponent(
592549
// TODO: current can be non-null here even if the component
593550
// hasn't yet mounted. This happens when the inner render suspends.
594551
// We'll need to figure out if this is fine or can cause issues.
595-
596-
if (__DEV__) {
597-
if (workInProgress.type !== workInProgress.elementType) {
598-
// Lazy component props can't be validated in createElement
599-
// because they're only guaranteed to be resolved here.
600-
let outerMemoType = workInProgress.elementType;
601-
if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
602-
// We warn when you define propTypes on lazy()
603-
// so let's just skip over it to find memo() outer wrapper.
604-
// Inner props for memo are validated later.
605-
const lazyComponent: LazyComponentType<any, any> = outerMemoType;
606-
const payload = lazyComponent._payload;
607-
const init = lazyComponent._init;
608-
try {
609-
outerMemoType = init(payload);
610-
} catch (x) {
611-
outerMemoType = null;
612-
}
613-
// Inner propTypes will be validated in the function component path.
614-
const outerPropTypes = outerMemoType && (outerMemoType: any).propTypes;
615-
if (outerPropTypes) {
616-
checkPropTypes(
617-
outerPropTypes,
618-
nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
619-
'prop',
620-
getComponentNameFromType(outerMemoType),
621-
);
622-
}
623-
}
624-
}
625-
}
626552
if (current !== null) {
627553
const prevProps = current.memoizedProps;
628554
if (
@@ -1099,22 +1025,6 @@ function updateFunctionComponent(
10991025
nextProps: any,
11001026
renderLanes: Lanes,
11011027
) {
1102-
if (__DEV__) {
1103-
if (workInProgress.type !== workInProgress.elementType) {
1104-
// Lazy component props can't be validated in createElement
1105-
// because they're only guaranteed to be resolved here.
1106-
const innerPropTypes = Component.propTypes;
1107-
if (innerPropTypes) {
1108-
checkPropTypes(
1109-
innerPropTypes,
1110-
nextProps, // Resolved props
1111-
'prop',
1112-
getComponentNameFromType(Component),
1113-
);
1114-
}
1115-
}
1116-
}
1117-
11181028
let context;
11191029
if (!disableLegacyContext) {
11201030
const unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
@@ -1253,20 +1163,6 @@ function updateClassComponent(
12531163
break;
12541164
}
12551165
}
1256-
1257-
if (workInProgress.type !== workInProgress.elementType) {
1258-
// Lazy component props can't be validated in createElement
1259-
// because they're only guaranteed to be resolved here.
1260-
const innerPropTypes = Component.propTypes;
1261-
if (innerPropTypes) {
1262-
checkPropTypes(
1263-
innerPropTypes,
1264-
nextProps, // Resolved props
1265-
'prop',
1266-
getComponentNameFromType(Component),
1267-
);
1268-
}
1269-
}
12701166
}
12711167

12721168
// Push context providers early to prevent context stack mismatches.
@@ -1815,19 +1711,6 @@ function mountLazyComponent(
18151711
return child;
18161712
}
18171713
case MemoComponent: {
1818-
if (__DEV__) {
1819-
if (workInProgress.type !== workInProgress.elementType) {
1820-
const outerPropTypes = Component.propTypes;
1821-
if (outerPropTypes) {
1822-
checkPropTypes(
1823-
outerPropTypes,
1824-
resolvedProps, // Resolved for outer only
1825-
'prop',
1826-
getComponentNameFromType(Component),
1827-
);
1828-
}
1829-
}
1830-
}
18311714
child = updateMemoComponent(
18321715
null,
18331716
workInProgress,
@@ -3549,11 +3432,6 @@ function updateContextProvider(
35493432
);
35503433
}
35513434
}
3552-
const providerPropTypes = workInProgress.type.propTypes;
3553-
3554-
if (providerPropTypes) {
3555-
checkPropTypes(providerPropTypes, newProps, 'prop', 'Context.Provider');
3556-
}
35573435
}
35583436

35593437
pushProvider(workInProgress, context, newValue);
@@ -4229,19 +4107,6 @@ function beginWork(
42294107
const unresolvedProps = workInProgress.pendingProps;
42304108
// Resolve outer props first, then resolve inner props.
42314109
let resolvedProps = resolveDefaultProps(type, unresolvedProps);
4232-
if (__DEV__) {
4233-
if (workInProgress.type !== workInProgress.elementType) {
4234-
const outerPropTypes = type.propTypes;
4235-
if (outerPropTypes) {
4236-
checkPropTypes(
4237-
outerPropTypes,
4238-
resolvedProps, // Resolved for outer only
4239-
'prop',
4240-
getComponentNameFromType(type),
4241-
);
4242-
}
4243-
}
4244-
}
42454110
resolvedProps = resolveDefaultProps(type.type, resolvedProps);
42464111
return updateMemoComponent(
42474112
current,

0 commit comments

Comments
 (0)