Skip to content

Commit 58d2bd8

Browse files
committed
[wip] remove prop types
1 parent d27c1ac commit 58d2bd8

21 files changed

+30
-847
lines changed

packages/react-art/npm/Circle.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
'use strict';
1919

2020
var assign = Object.assign;
21-
var PropTypes = require('prop-types');
2221
var React = require('react');
2322
var ReactART = require('react-art');
2423

@@ -34,10 +33,6 @@ var Shape = ReactART.Shape;
3433
var Circle = createReactClass({
3534
displayName: 'Circle',
3635

37-
propTypes: {
38-
radius: PropTypes.number.isRequired,
39-
},
40-
4136
render: function render() {
4237
var radius = this.props.radius;
4338

packages/react-art/npm/Rectangle.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
'use strict';
2626

2727
var assign = Object.assign;
28-
var PropTypes = require('prop-types');
2928
var React = require('react');
3029
var ReactART = require('react-art');
3130

@@ -41,16 +40,6 @@ var Path = ReactART.Path;
4140
var Rectangle = createReactClass({
4241
displayName: 'Rectangle',
4342

44-
propTypes: {
45-
width: PropTypes.number.isRequired,
46-
height: PropTypes.number.isRequired,
47-
radius: PropTypes.number,
48-
radiusTopLeft: PropTypes.number,
49-
radiusTopRight: PropTypes.number,
50-
radiusBottomRight: PropTypes.number,
51-
radiusBottomLeft: PropTypes.number,
52-
},
53-
5443
render: function render() {
5544
var width = this.props.width;
5645
var height = this.props.height;

packages/react-art/npm/Wedge.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
'use strict';
2222

2323
var assign = Object.assign;
24-
var PropTypes = require('prop-types');
2524
var React = require('react');
2625
var ReactART = require('react-art');
2726

@@ -37,13 +36,6 @@ var Path = ReactART.Path;
3736
var Wedge = createReactClass({
3837
displayName: 'Wedge',
3938

40-
propTypes: {
41-
outerRadius: PropTypes.number.isRequired,
42-
startAngle: PropTypes.number.isRequired,
43-
endAngle: PropTypes.number.isRequired,
44-
innerRadius: PropTypes.number,
45-
},
46-
4739
circleRadians: Math.PI * 2,
4840

4941
radiansPerDegree: Math.PI / 180,

packages/react-art/src/__tests__/ReactART-test.js

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,6 @@ describe('ReactARTComponents', () => {
461461
expect(circle.toJSON()).toMatchSnapshot();
462462
});
463463

464-
it('should warn if radius is missing on a Circle component', () => {
465-
expect(() =>
466-
ReactTestRenderer.create(
467-
<Circle stroke="green" strokeWidth={3} fill="blue" />,
468-
),
469-
).toErrorDev(
470-
'Warning: Failed prop type: The prop `radius` is marked as required in `Circle`, ' +
471-
'but its value is `undefined`.' +
472-
'\n in Circle (at **)',
473-
);
474-
});
475-
476464
it('should generate a <Shape> with props for drawing the Rectangle', () => {
477465
const rectangle = ReactTestRenderer.create(
478466
<Rectangle width={50} height={50} stroke="green" fill="blue" />,
@@ -534,19 +522,6 @@ describe('ReactARTComponents', () => {
534522
expect(rectangle.toJSON()).toMatchSnapshot();
535523
});
536524

537-
it('should warn if width/height is missing on a Rectangle component', () => {
538-
expect(() =>
539-
ReactTestRenderer.create(<Rectangle stroke="green" fill="blue" />),
540-
).toErrorDev([
541-
'Warning: Failed prop type: The prop `width` is marked as required in `Rectangle`, ' +
542-
'but its value is `undefined`.' +
543-
'\n in Rectangle (at **)',
544-
'Warning: Failed prop type: The prop `height` is marked as required in `Rectangle`, ' +
545-
'but its value is `undefined`.' +
546-
'\n in Rectangle (at **)',
547-
]);
548-
});
549-
550525
it('should generate a <Shape> with props for drawing the Wedge', () => {
551526
const wedge = ReactTestRenderer.create(
552527
<Wedge outerRadius={50} startAngle={0} endAngle={360} fill="blue" />,
@@ -560,18 +535,4 @@ describe('ReactARTComponents', () => {
560535
);
561536
expect(wedge.toJSON()).toBeNull();
562537
});
563-
564-
it('should warn if outerRadius/startAngle/endAngle is missing on a Wedge component', () => {
565-
expect(() => ReactTestRenderer.create(<Wedge fill="blue" />)).toErrorDev([
566-
'Warning: Failed prop type: The prop `outerRadius` is marked as required in `Wedge`, ' +
567-
'but its value is `undefined`.' +
568-
'\n in Wedge (at **)',
569-
'Warning: Failed prop type: The prop `startAngle` is marked as required in `Wedge`, ' +
570-
'but its value is `undefined`.' +
571-
'\n in Wedge (at **)',
572-
'Warning: Failed prop type: The prop `endAngle` is marked as required in `Wedge`, ' +
573-
'but its value is `undefined`.' +
574-
'\n in Wedge (at **)',
575-
]);
576-
});
577538
});

packages/react-dom/src/__tests__/ReactFunctionComponent-test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,9 @@ describe('ReactFunctionComponent', () => {
386386
return <div>{props.test}</div>;
387387
}
388388
Child.defaultProps = {test: 2};
389-
Child.propTypes = {test: PropTypes.string};
390389

391390
expect(() => ReactTestUtils.renderIntoDocument(<Child />)).toErrorDev([
392391
'Warning: Child: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.',
393-
'Warning: Failed prop type: Invalid prop `test` of type `number` ' +
394-
'supplied to `Child`, expected `string`.\n' +
395-
' in Child (at **)',
396392
]);
397393
});
398394

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 0 additions & 135 deletions
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,22 +400,6 @@ function updateForwardRef(
401400
// hasn't yet mounted. This happens after the first render suspends.
402401
// We'll need to figure out if this is fine or can cause issues.
403402

404-
if (__DEV__) {
405-
if (workInProgress.type !== workInProgress.elementType) {
406-
// Lazy component props can't be validated in createElement
407-
// because they're only guaranteed to be resolved here.
408-
const innerPropTypes = Component.propTypes;
409-
if (innerPropTypes) {
410-
checkPropTypes(
411-
innerPropTypes,
412-
nextProps, // Resolved props
413-
'prop',
414-
getComponentNameFromType(Component),
415-
);
416-
}
417-
}
418-
}
419-
420403
const render = Component.render;
421404
const ref = workInProgress.ref;
422405

@@ -506,17 +489,6 @@ function updateMemoComponent(
506489
);
507490
}
508491
if (__DEV__) {
509-
const innerPropTypes = type.propTypes;
510-
if (innerPropTypes) {
511-
// Inner memo component props aren't currently validated in createElement.
512-
// We could move it there, but we'd still need this for lazy code path.
513-
checkPropTypes(
514-
innerPropTypes,
515-
nextProps, // Resolved props
516-
'prop',
517-
getComponentNameFromType(type),
518-
);
519-
}
520492
if (Component.defaultProps !== undefined) {
521493
const componentName = getComponentNameFromType(type) || 'Unknown';
522494
if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) {
@@ -542,20 +514,6 @@ function updateMemoComponent(
542514
workInProgress.child = child;
543515
return child;
544516
}
545-
if (__DEV__) {
546-
const type = Component.type;
547-
const innerPropTypes = type.propTypes;
548-
if (innerPropTypes) {
549-
// Inner memo component props aren't currently validated in createElement.
550-
// We could move it there, but we'd still need this for lazy code path.
551-
checkPropTypes(
552-
innerPropTypes,
553-
nextProps, // Resolved props
554-
'prop',
555-
getComponentNameFromType(type),
556-
);
557-
}
558-
}
559517
const currentChild = ((current.child: any): Fiber); // This is always exactly one child
560518
const hasScheduledUpdateOrContext = checkScheduledUpdateOrContext(
561519
current,
@@ -591,37 +549,6 @@ function updateSimpleMemoComponent(
591549
// TODO: current can be non-null here even if the component
592550
// hasn't yet mounted. This happens when the inner render suspends.
593551
// We'll need to figure out if this is fine or can cause issues.
594-
595-
if (__DEV__) {
596-
if (workInProgress.type !== workInProgress.elementType) {
597-
// Lazy component props can't be validated in createElement
598-
// because they're only guaranteed to be resolved here.
599-
let outerMemoType = workInProgress.elementType;
600-
if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
601-
// We warn when you define propTypes on lazy()
602-
// so let's just skip over it to find memo() outer wrapper.
603-
// Inner props for memo are validated later.
604-
const lazyComponent: LazyComponentType<any, any> = outerMemoType;
605-
const payload = lazyComponent._payload;
606-
const init = lazyComponent._init;
607-
try {
608-
outerMemoType = init(payload);
609-
} catch (x) {
610-
outerMemoType = null;
611-
}
612-
// Inner propTypes will be validated in the function component path.
613-
const outerPropTypes = outerMemoType && (outerMemoType: any).propTypes;
614-
if (outerPropTypes) {
615-
checkPropTypes(
616-
outerPropTypes,
617-
nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
618-
'prop',
619-
getComponentNameFromType(outerMemoType),
620-
);
621-
}
622-
}
623-
}
624-
}
625552
if (current !== null) {
626553
const prevProps = current.memoizedProps;
627554
if (
@@ -1098,22 +1025,6 @@ function updateFunctionComponent(
10981025
nextProps: any,
10991026
renderLanes: Lanes,
11001027
) {
1101-
if (__DEV__) {
1102-
if (workInProgress.type !== workInProgress.elementType) {
1103-
// Lazy component props can't be validated in createElement
1104-
// because they're only guaranteed to be resolved here.
1105-
const innerPropTypes = Component.propTypes;
1106-
if (innerPropTypes) {
1107-
checkPropTypes(
1108-
innerPropTypes,
1109-
nextProps, // Resolved props
1110-
'prop',
1111-
getComponentNameFromType(Component),
1112-
);
1113-
}
1114-
}
1115-
}
1116-
11171028
let context;
11181029
if (!disableLegacyContext) {
11191030
const unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
@@ -1252,20 +1163,6 @@ function updateClassComponent(
12521163
break;
12531164
}
12541165
}
1255-
1256-
if (workInProgress.type !== workInProgress.elementType) {
1257-
// Lazy component props can't be validated in createElement
1258-
// because they're only guaranteed to be resolved here.
1259-
const innerPropTypes = Component.propTypes;
1260-
if (innerPropTypes) {
1261-
checkPropTypes(
1262-
innerPropTypes,
1263-
nextProps, // Resolved props
1264-
'prop',
1265-
getComponentNameFromType(Component),
1266-
);
1267-
}
1268-
}
12691166
}
12701167

12711168
// Push context providers early to prevent context stack mismatches.
@@ -1814,19 +1711,6 @@ function mountLazyComponent(
18141711
return child;
18151712
}
18161713
case MemoComponent: {
1817-
if (__DEV__) {
1818-
if (workInProgress.type !== workInProgress.elementType) {
1819-
const outerPropTypes = Component.propTypes;
1820-
if (outerPropTypes) {
1821-
checkPropTypes(
1822-
outerPropTypes,
1823-
resolvedProps, // Resolved for outer only
1824-
'prop',
1825-
getComponentNameFromType(Component),
1826-
);
1827-
}
1828-
}
1829-
}
18301714
child = updateMemoComponent(
18311715
null,
18321716
workInProgress,
@@ -3545,13 +3429,7 @@ function updateContextProvider(
35453429
);
35463430
}
35473431
}
3548-
const providerPropTypes = workInProgress.type.propTypes;
3549-
3550-
if (providerPropTypes) {
3551-
checkPropTypes(providerPropTypes, newProps, 'prop', 'Context.Provider');
3552-
}
35533432
}
3554-
35553433
pushProvider(workInProgress, context, newValue);
35563434

35573435
if (enableLazyContextPropagation) {
@@ -4232,19 +4110,6 @@ function beginWork(
42324110
const unresolvedProps = workInProgress.pendingProps;
42334111
// Resolve outer props first, then resolve inner props.
42344112
let resolvedProps = resolveDefaultProps(type, unresolvedProps);
4235-
if (__DEV__) {
4236-
if (workInProgress.type !== workInProgress.elementType) {
4237-
const outerPropTypes = type.propTypes;
4238-
if (outerPropTypes) {
4239-
checkPropTypes(
4240-
outerPropTypes,
4241-
resolvedProps, // Resolved for outer only
4242-
'prop',
4243-
getComponentNameFromType(type),
4244-
);
4245-
}
4246-
}
4247-
}
42484113
resolvedProps = resolveDefaultProps(type.type, resolvedProps);
42494114
return updateMemoComponent(
42504115
current,

packages/react-reconciler/src/ReactFiberClassComponent.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,6 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
395395
name,
396396
);
397397
}
398-
if (instance.propTypes) {
399-
console.error(
400-
'propTypes was defined as an instance property on %s. Use a static ' +
401-
'property to define propTypes instead.',
402-
name,
403-
);
404-
}
405398
if (instance.contextType) {
406399
console.error(
407400
'contextType was defined as an instance property on %s. Use a static ' +

packages/react-reconciler/src/ReactFiberContext.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {isFiberMounted} from './ReactFiberTreeReflection';
1414
import {disableLegacyContext} from 'shared/ReactFeatureFlags';
1515
import {ClassComponent, HostRoot} from './ReactWorkTags';
1616
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
17-
import checkPropTypes from 'shared/checkPropTypes';
17+
import checkContextPropTypes from 'shared/checkContextPropTypes';
1818

1919
import {createCursor, push, pop} from './ReactFiberStack';
2020

@@ -103,7 +103,7 @@ function getMaskedContext(
103103

104104
if (__DEV__) {
105105
const name = getComponentNameFromFiber(workInProgress) || 'Unknown';
106-
checkPropTypes(contextTypes, context, 'context', name);
106+
checkContextPropTypes(contextTypes, context, 'context', name);
107107
}
108108

109109
// Cache unmasked context so we can avoid recreating masked context unless necessary.
@@ -214,7 +214,12 @@ function processChildContext(
214214
}
215215
if (__DEV__) {
216216
const name = getComponentNameFromFiber(fiber) || 'Unknown';
217-
checkPropTypes(childContextTypes, childContext, 'child context', name);
217+
checkContextPropTypes(
218+
childContextTypes,
219+
childContext,
220+
'child context',
221+
name,
222+
);
218223
}
219224

220225
return {...parentContext, ...childContext};

0 commit comments

Comments
 (0)