Skip to content

Commit

Permalink
[wip] remove prop types
Browse files Browse the repository at this point in the history
  • Loading branch information
kassens committed Feb 2, 2024
1 parent 4b2a111 commit 7b85bc9
Show file tree
Hide file tree
Showing 19 changed files with 14 additions and 838 deletions.
5 changes: 0 additions & 5 deletions packages/react-art/npm/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
'use strict';

var assign = Object.assign;
var PropTypes = require('prop-types');
var React = require('react');
var ReactART = require('react-art');

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

propTypes: {
radius: PropTypes.number.isRequired,
},

render: function render() {
var radius = this.props.radius;

Expand Down
11 changes: 0 additions & 11 deletions packages/react-art/npm/Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
'use strict';

var assign = Object.assign;
var PropTypes = require('prop-types');
var React = require('react');
var ReactART = require('react-art');

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

propTypes: {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
radius: PropTypes.number,
radiusTopLeft: PropTypes.number,
radiusTopRight: PropTypes.number,
radiusBottomRight: PropTypes.number,
radiusBottomLeft: PropTypes.number,
},

render: function render() {
var width = this.props.width;
var height = this.props.height;
Expand Down
8 changes: 0 additions & 8 deletions packages/react-art/npm/Wedge.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
'use strict';

var assign = Object.assign;
var PropTypes = require('prop-types');
var React = require('react');
var ReactART = require('react-art');

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

propTypes: {
outerRadius: PropTypes.number.isRequired,
startAngle: PropTypes.number.isRequired,
endAngle: PropTypes.number.isRequired,
innerRadius: PropTypes.number,
},

circleRadians: Math.PI * 2,

radiansPerDegree: Math.PI / 180,
Expand Down
39 changes: 0 additions & 39 deletions packages/react-art/src/__tests__/ReactART-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,18 +456,6 @@ describe('ReactARTComponents', () => {
expect(circle.toJSON()).toMatchSnapshot();
});

it('should warn if radius is missing on a Circle component', () => {
expect(() =>
ReactTestRenderer.create(
<Circle stroke="green" strokeWidth={3} fill="blue" />,
),
).toErrorDev(
'Warning: Failed prop type: The prop `radius` is marked as required in `Circle`, ' +
'but its value is `undefined`.' +
'\n in Circle (at **)',
);
});

it('should generate a <Shape> with props for drawing the Rectangle', () => {
const rectangle = ReactTestRenderer.create(
<Rectangle width={50} height={50} stroke="green" fill="blue" />,
Expand Down Expand Up @@ -529,19 +517,6 @@ describe('ReactARTComponents', () => {
expect(rectangle.toJSON()).toMatchSnapshot();
});

it('should warn if width/height is missing on a Rectangle component', () => {
expect(() =>
ReactTestRenderer.create(<Rectangle stroke="green" fill="blue" />),
).toErrorDev([
'Warning: Failed prop type: The prop `width` is marked as required in `Rectangle`, ' +
'but its value is `undefined`.' +
'\n in Rectangle (at **)',
'Warning: Failed prop type: The prop `height` is marked as required in `Rectangle`, ' +
'but its value is `undefined`.' +
'\n in Rectangle (at **)',
]);
});

it('should generate a <Shape> with props for drawing the Wedge', () => {
const wedge = ReactTestRenderer.create(
<Wedge outerRadius={50} startAngle={0} endAngle={360} fill="blue" />,
Expand All @@ -555,18 +530,4 @@ describe('ReactARTComponents', () => {
);
expect(wedge.toJSON()).toBeNull();
});

it('should warn if outerRadius/startAngle/endAngle is missing on a Wedge component', () => {
expect(() => ReactTestRenderer.create(<Wedge fill="blue" />)).toErrorDev([
'Warning: Failed prop type: The prop `outerRadius` is marked as required in `Wedge`, ' +
'but its value is `undefined`.' +
'\n in Wedge (at **)',
'Warning: Failed prop type: The prop `startAngle` is marked as required in `Wedge`, ' +
'but its value is `undefined`.' +
'\n in Wedge (at **)',
'Warning: Failed prop type: The prop `endAngle` is marked as required in `Wedge`, ' +
'but its value is `undefined`.' +
'\n in Wedge (at **)',
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,9 @@ describe('ReactFunctionComponent', () => {
return <div>{props.test}</div>;
}
Child.defaultProps = {test: 2};
Child.propTypes = {test: PropTypes.string};

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

Expand Down
128 changes: 0 additions & 128 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,22 +401,6 @@ function updateForwardRef(
// hasn't yet mounted. This happens after the first render suspends.
// We'll need to figure out if this is fine or can cause issues.

if (__DEV__) {
if (workInProgress.type !== workInProgress.elementType) {
// Lazy component props can't be validated in createElement
// because they're only guaranteed to be resolved here.
const innerPropTypes = Component.propTypes;
if (innerPropTypes) {
checkPropTypes(
innerPropTypes,
nextProps, // Resolved props
'prop',
getComponentNameFromType(Component),
);
}
}
}

const render = Component.render;
const ref = workInProgress.ref;

Expand Down Expand Up @@ -506,17 +490,6 @@ function updateMemoComponent(
);
}
if (__DEV__) {
const innerPropTypes = type.propTypes;
if (innerPropTypes) {
// Inner memo component props aren't currently validated in createElement.
// We could move it there, but we'd still need this for lazy code path.
checkPropTypes(
innerPropTypes,
nextProps, // Resolved props
'prop',
getComponentNameFromType(type),
);
}
if (Component.defaultProps !== undefined) {
const componentName = getComponentNameFromType(type) || 'Unknown';
if (!didWarnAboutDefaultPropsOnFunctionComponent[componentName]) {
Expand All @@ -543,20 +516,6 @@ function updateMemoComponent(
workInProgress.child = child;
return child;
}
if (__DEV__) {
const type = Component.type;
const innerPropTypes = type.propTypes;
if (innerPropTypes) {
// Inner memo component props aren't currently validated in createElement.
// We could move it there, but we'd still need this for lazy code path.
checkPropTypes(
innerPropTypes,
nextProps, // Resolved props
'prop',
getComponentNameFromType(type),
);
}
}
const currentChild = ((current.child: any): Fiber); // This is always exactly one child
const hasScheduledUpdateOrContext = checkScheduledUpdateOrContext(
current,
Expand Down Expand Up @@ -592,37 +551,6 @@ function updateSimpleMemoComponent(
// TODO: current can be non-null here even if the component
// hasn't yet mounted. This happens when the inner render suspends.
// We'll need to figure out if this is fine or can cause issues.

if (__DEV__) {
if (workInProgress.type !== workInProgress.elementType) {
// Lazy component props can't be validated in createElement
// because they're only guaranteed to be resolved here.
let outerMemoType = workInProgress.elementType;
if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
// We warn when you define propTypes on lazy()
// so let's just skip over it to find memo() outer wrapper.
// Inner props for memo are validated later.
const lazyComponent: LazyComponentType<any, any> = outerMemoType;
const payload = lazyComponent._payload;
const init = lazyComponent._init;
try {
outerMemoType = init(payload);
} catch (x) {
outerMemoType = null;
}
// Inner propTypes will be validated in the function component path.
const outerPropTypes = outerMemoType && (outerMemoType: any).propTypes;
if (outerPropTypes) {
checkPropTypes(
outerPropTypes,
nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
'prop',
getComponentNameFromType(outerMemoType),
);
}
}
}
}
if (current !== null) {
const prevProps = current.memoizedProps;
if (
Expand Down Expand Up @@ -1099,22 +1027,6 @@ function updateFunctionComponent(
nextProps: any,
renderLanes: Lanes,
) {
if (__DEV__) {
if (workInProgress.type !== workInProgress.elementType) {
// Lazy component props can't be validated in createElement
// because they're only guaranteed to be resolved here.
const innerPropTypes = Component.propTypes;
if (innerPropTypes) {
checkPropTypes(
innerPropTypes,
nextProps, // Resolved props
'prop',
getComponentNameFromType(Component),
);
}
}
}

let context;
if (!disableLegacyContext) {
const unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
Expand Down Expand Up @@ -1253,20 +1165,6 @@ function updateClassComponent(
break;
}
}

if (workInProgress.type !== workInProgress.elementType) {
// Lazy component props can't be validated in createElement
// because they're only guaranteed to be resolved here.
const innerPropTypes = Component.propTypes;
if (innerPropTypes) {
checkPropTypes(
innerPropTypes,
nextProps, // Resolved props
'prop',
getComponentNameFromType(Component),
);
}
}
}

// Push context providers early to prevent context stack mismatches.
Expand Down Expand Up @@ -1815,19 +1713,6 @@ function mountLazyComponent(
return child;
}
case MemoComponent: {
if (__DEV__) {
if (workInProgress.type !== workInProgress.elementType) {
const outerPropTypes = Component.propTypes;
if (outerPropTypes) {
checkPropTypes(
outerPropTypes,
resolvedProps, // Resolved for outer only
'prop',
getComponentNameFromType(Component),
);
}
}
}
child = updateMemoComponent(
null,
workInProgress,
Expand Down Expand Up @@ -4237,19 +4122,6 @@ function beginWork(
const unresolvedProps = workInProgress.pendingProps;
// Resolve outer props first, then resolve inner props.
let resolvedProps = resolveDefaultProps(type, unresolvedProps);
if (__DEV__) {
if (workInProgress.type !== workInProgress.elementType) {
const outerPropTypes = type.propTypes;
if (outerPropTypes) {
checkPropTypes(
outerPropTypes,
resolvedProps, // Resolved for outer only
'prop',
getComponentNameFromType(type),
);
}
}
}
resolvedProps = resolveDefaultProps(type.type, resolvedProps);
return updateMemoComponent(
current,
Expand Down
7 changes: 0 additions & 7 deletions packages/react-reconciler/src/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,6 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
name,
);
}
if (instance.propTypes) {
console.error(
'propTypes was defined as an instance property on %s. Use a static ' +
'property to define propTypes instead.',
name,
);
}
if (instance.contextType) {
console.error(
'contextType was defined as an instance property on %s. Use a static ' +
Expand Down
Loading

0 comments on commit 7b85bc9

Please sign in to comment.