Skip to content

Commit e4cd101

Browse files
keyzzpao
authored andcommitted
Remove prop types checking in ReactCompositeComponent (facebook#6824)
Remove prop types checking in ReactCompositeComponent (cherry picked from commit c136369)
1 parent 56ead57 commit e4cd101

File tree

2 files changed

+19
-58
lines changed

2 files changed

+19
-58
lines changed

src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -849,9 +849,8 @@ describe('ReactPropTypes', function() {
849849
var instance = <Component num={5} />;
850850
instance = ReactTestUtils.renderIntoDocument(instance);
851851

852-
expect(spy.argsForCall.length).toBe(2); // temp double validation
852+
expect(spy.argsForCall.length).toBe(1);
853853
expect(spy.argsForCall[0][1]).toBe('num');
854-
expect(spy.argsForCall[0][2]).toBe('Component');
855854
});
856855

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

870-
expect(spy.argsForCall.length).toBe(2); // temp double validation
869+
expect(spy.argsForCall.length).toBe(1);
870+
expect(spy.argsForCall[0][1]).toBe('num');
871871
});
872872

873873
it('should have received the validator\'s return value', function() {

src/renderers/shared/stack/reconciler/ReactCompositeComponent.js

+16-55
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ var ReactCompositeComponentMixin = {
197197
this._hostParent = hostParent;
198198
this._hostContainerInfo = hostContainerInfo;
199199

200-
var publicProps = this._processProps(this._currentElement.props);
200+
var publicProps = this._currentElement.props;
201201
var publicContext = this._processContext(context);
202202

203203
var Component = this._currentElement.type;
@@ -614,7 +614,7 @@ var ReactCompositeComponentMixin = {
614614
if (__DEV__) {
615615
var Component = this._currentElement.type;
616616
if (Component.contextTypes) {
617-
this._checkPropTypes(
617+
this._checkContextTypes(
618618
Component.contextTypes,
619619
maskedContext,
620620
ReactPropTypeLocations.context
@@ -647,7 +647,7 @@ var ReactCompositeComponentMixin = {
647647
this.getName() || 'ReactCompositeComponent'
648648
);
649649
if (__DEV__) {
650-
this._checkPropTypes(
650+
this._checkContextTypes(
651651
Component.childContextTypes,
652652
childContext,
653653
ReactPropTypeLocations.childContext
@@ -667,39 +667,14 @@ var ReactCompositeComponentMixin = {
667667
},
668668

669669
/**
670-
* Processes props by setting default values for unspecified props and
671-
* asserting that the props are valid. Does not mutate its argument; returns
672-
* a new props object with defaults merged in.
670+
* Assert that the context types are valid
673671
*
674-
* @param {object} newProps
675-
* @return {object}
676-
* @private
677-
*/
678-
_processProps: function(newProps) {
679-
if (__DEV__) {
680-
var Component = this._currentElement.type;
681-
if (Component.propTypes) {
682-
this._checkPropTypes(
683-
Component.propTypes,
684-
newProps,
685-
ReactPropTypeLocations.prop
686-
);
687-
}
688-
}
689-
return newProps;
690-
},
691-
692-
/**
693-
* Assert that the props are valid
694-
*
695-
* @param {object} propTypes Map of prop name to a ReactPropType
672+
* @param {object} propTypes Map of context field to a ReactPropType
696673
* @param {object} props
697674
* @param {string} location e.g. "prop", "context", "child context"
698675
* @private
699676
*/
700-
_checkPropTypes: function(propTypes, props, location) {
701-
// TODO: Stop validating prop types here and only use the element
702-
// validation.
677+
_checkContextTypes: function(propTypes, props, location) {
703678
var componentName = this.getName();
704679
for (var propName in propTypes) {
705680
if (propTypes.hasOwnProperty(propName)) {
@@ -724,23 +699,12 @@ var ReactCompositeComponentMixin = {
724699
// top-level render calls, so I'm abstracting it away into
725700
// a function to minimize refactoring in the future
726701
var addendum = getDeclarationErrorAddendum(this);
727-
728-
if (location === ReactPropTypeLocations.prop) {
729-
// Preface gives us something to blacklist in warning module
730-
warning(
731-
false,
732-
'Failed Composite propType: %s%s',
733-
error.message,
734-
addendum
735-
);
736-
} else {
737-
warning(
738-
false,
739-
'Failed Context Types: %s%s',
740-
error.message,
741-
addendum
742-
);
743-
}
702+
warning(
703+
false,
704+
'Failed Context Types: %s%s',
705+
error.message,
706+
addendum
707+
);
744708
}
745709
}
746710
}
@@ -824,13 +788,10 @@ var ReactCompositeComponentMixin = {
824788
willReceive = true;
825789
}
826790

827-
// Distinguish between a props update versus a simple state update
828-
if (prevParentElement === nextParentElement) {
829-
// Skip checking prop types again -- we don't read inst.props to avoid
830-
// warning for DOM component props in this upgrade
831-
nextProps = nextParentElement.props;
832-
} else {
833-
nextProps = this._processProps(nextParentElement.props);
791+
nextProps = nextParentElement.props;
792+
793+
// Not a simple state update but a props update
794+
if (prevParentElement !== nextParentElement) {
834795
willReceive = true;
835796
}
836797

0 commit comments

Comments
 (0)