Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove prop types checking in ReactCompositeComponent #6824

Merged
merged 2 commits into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,8 @@ describe('ReactPropTypes', function() {
var instance = <Component num={5} />;
instance = ReactTestUtils.renderIntoDocument(instance);

expect(spy.argsForCall.length).toBe(2); // temp double validation
expect(spy.argsForCall.length).toBe(1);
expect(spy.argsForCall[0][1]).toBe('num');
expect(spy.argsForCall[0][2]).toBe('Component');
});

it('should have been called even if the prop is not present', function() {
Expand All @@ -867,7 +866,8 @@ describe('ReactPropTypes', function() {
var instance = <Component bla={5} />;
instance = ReactTestUtils.renderIntoDocument(instance);

expect(spy.argsForCall.length).toBe(2); // temp double validation
expect(spy.argsForCall.length).toBe(1);
expect(spy.argsForCall[0][1]).toBe('num');
});

it('should have received the validator\'s return value', function() {
Expand Down
71 changes: 16 additions & 55 deletions src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ var ReactCompositeComponentMixin = {
this._hostParent = hostParent;
this._hostContainerInfo = hostContainerInfo;

var publicProps = this._processProps(this._currentElement.props);
var publicProps = this._currentElement.props;
var publicContext = this._processContext(context);

var Component = this._currentElement.type;
Expand Down Expand Up @@ -614,7 +614,7 @@ var ReactCompositeComponentMixin = {
if (__DEV__) {
var Component = this._currentElement.type;
if (Component.contextTypes) {
this._checkPropTypes(
this._checkContextTypes(
Component.contextTypes,
maskedContext,
ReactPropTypeLocations.context
Expand Down Expand Up @@ -647,7 +647,7 @@ var ReactCompositeComponentMixin = {
this.getName() || 'ReactCompositeComponent'
);
if (__DEV__) {
this._checkPropTypes(
this._checkContextTypes(
Component.childContextTypes,
childContext,
ReactPropTypeLocations.childContext
Expand All @@ -667,39 +667,14 @@ var ReactCompositeComponentMixin = {
},

/**
* Processes props by setting default values for unspecified props and
* asserting that the props are valid. Does not mutate its argument; returns
* a new props object with defaults merged in.
* Assert that the context types are valid
*
* @param {object} newProps
* @return {object}
* @private
*/
_processProps: function(newProps) {
if (__DEV__) {
var Component = this._currentElement.type;
if (Component.propTypes) {
this._checkPropTypes(
Component.propTypes,
newProps,
ReactPropTypeLocations.prop
);
}
}
return newProps;
},

/**
* Assert that the props are valid
*
* @param {object} propTypes Map of prop name to a ReactPropType
* @param {object} propTypes Map of context field to a ReactPropType
* @param {object} props
* @param {string} location e.g. "prop", "context", "child context"
* @private
*/
_checkPropTypes: function(propTypes, props, location) {
// TODO: Stop validating prop types here and only use the element
// validation.
_checkContextTypes: function(propTypes, props, location) {
var componentName = this.getName();
for (var propName in propTypes) {
if (propTypes.hasOwnProperty(propName)) {
Expand All @@ -724,23 +699,12 @@ var ReactCompositeComponentMixin = {
// top-level render calls, so I'm abstracting it away into
// a function to minimize refactoring in the future
var addendum = getDeclarationErrorAddendum(this);

if (location === ReactPropTypeLocations.prop) {
// Preface gives us something to blacklist in warning module
warning(
false,
'Failed Composite propType: %s%s',
error.message,
addendum
);
} else {
warning(
false,
'Failed Context Types: %s%s',
error.message,
addendum
);
}
warning(
false,
'Failed Context Types: %s%s',
error.message,
addendum
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind switching this to use getStackAddendumByID to show the stack? That can be a separate PR if you prefer.

);
}
}
}
Expand Down Expand Up @@ -824,13 +788,10 @@ var ReactCompositeComponentMixin = {
willReceive = true;
}

// Distinguish between a props update versus a simple state update
if (prevParentElement === nextParentElement) {
// Skip checking prop types again -- we don't read inst.props to avoid
// warning for DOM component props in this upgrade
nextProps = nextParentElement.props;
} else {
nextProps = this._processProps(nextParentElement.props);
nextProps = nextParentElement.props;

// Not a simple state update but a props update
if (prevParentElement !== nextParentElement) {
willReceive = true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you simplify this to

nextProps = nextParentElement.props;
if (prevParentElement !== nextParentElement) {
  willReceive = true;
}

now?


Expand Down