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

Re-add the warning if PropType function is called manually #8903

Merged
merged 3 commits into from
Feb 8, 2017
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
10 changes: 10 additions & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,11 @@ src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
* should not warn for valid values
* should be implicitly optional and not warn without values
* should warn for missing required values
* should warn if called manually in development
* should should accept any value
* should be implicitly optional and not warn without values
* should warn for missing required values
* should warn if called manually in development
* should fail for invalid argument
* should support the arrayOf propTypes
* should support arrayOf with complex types
Expand All @@ -325,23 +327,27 @@ src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
* should not warn when passing an empty array
* should be implicitly optional and not warn without values
* should warn for missing required values
* should warn if called manually in development
* should support components
* should not support multiple components or scalar values
* should be able to define a single child as label
* should warn when passing no label and isRequired is set
* should be implicitly optional and not warn without values
* should warn for missing required values
* should warn if called manually in development
* should warn for invalid instances
* should not warn for valid values
* should be implicitly optional and not warn without values
* should warn for missing required values
* should warn if called manually in development
* should warn for invalid values
* should not warn for valid values
* should not warn for iterables
* should not warn for entry iterables
* should not warn for null/undefined if not required
* should warn for missing required values
* should accept empty array for required props
* should warn if called manually in development
* should fail for invalid argument
* should support the objectOf propTypes
* should support objectOf with complex types
Expand All @@ -351,16 +357,19 @@ src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
* should not warn when passing an empty object
* should be implicitly optional and not warn without values
* should warn for missing required values
* should warn if called manually in development
* should warn but not error for invalid argument
* should warn for invalid values
* should not warn for valid values
* should be implicitly optional and not warn without values
* should warn for missing required values
* should warn if called manually in development
* should warn but not error for invalid argument
* should warn if none of the types are valid
* should not warn if one of the types are valid
* should be implicitly optional and not warn without values
* should warn for missing required values
* should warn if called manually in development
* should warn for non objects
* should not warn for empty values
* should not warn for an empty object
Expand All @@ -371,6 +380,7 @@ src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
* should warn for invalid key types
* should be implicitly optional and not warn without values
* should warn for missing required values
* should warn if called manually in development
* should warn for non-symbol
* should not warn for a polyfilled Symbol
* should have been called with the right params
Expand Down
64 changes: 57 additions & 7 deletions src/isomorphic/classic/types/ReactPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

var ReactElement = require('ReactElement');
var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
var ReactPropTypesSecret = require('ReactPropTypesSecret');

var emptyFunction = require('emptyFunction');
var getIteratorFn = require('getIteratorFn');
Expand Down Expand Up @@ -154,16 +155,42 @@ function PropTypeError(message) {
PropTypeError.prototype = Error.prototype;

function createChainableTypeChecker(validate) {
if (__DEV__) {
var manualPropTypeCallCache = {};
}
function checkType(
isRequired,
props,
propName,
componentName,
location,
propFullName
propFullName,
secret
) {
componentName = componentName || ANONYMOUS;
propFullName = propFullName || propName;
if (__DEV__) {
if (
secret !== ReactPropTypesSecret &&
typeof console !== 'undefined'
) {
var cacheKey = `${componentName}:${propName}`;
if (!manualPropTypeCallCache[cacheKey]) {
warning(
false,
'You are manually calling a React.PropTypes validation ' +
'function for the `%s` prop on `%s`. This is deprecated ' +
'and will not work in production with the next major version. ' +
'You may be seeing this warning due to a third-party PropTypes ' +
'library. See https://fb.me/react-warning-dont-call-proptypes ' +
'for details.',
propFullName,
componentName
);
manualPropTypeCallCache[cacheKey] = true;
}
}
}
if (props[propName] == null) {
var locationName = ReactPropTypeLocationNames[location];
if (isRequired) {
Expand All @@ -180,7 +207,13 @@ function createChainableTypeChecker(validate) {
}
return null;
} else {
return validate(props, propName, componentName, location, propFullName);
return validate(
props,
propName,
componentName,
location,
propFullName,
);
}
}

Expand All @@ -191,7 +224,14 @@ function createChainableTypeChecker(validate) {
}

function createPrimitiveTypeChecker(expectedType) {
function validate(props, propName, componentName, location, propFullName) {
function validate(
props,
propName,
componentName,
location,
propFullName,
secret
) {
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== expectedType) {
Expand Down Expand Up @@ -238,7 +278,8 @@ function createArrayOfTypeChecker(typeChecker) {
i,
componentName,
location,
`${propFullName}[${i}]`
`${propFullName}[${i}]`,
ReactPropTypesSecret
);
if (error instanceof Error) {
return error;
Expand Down Expand Up @@ -329,7 +370,8 @@ function createObjectOfTypeChecker(typeChecker) {
key,
componentName,
location,
`${propFullName}.${key}`
`${propFullName}.${key}`,
ReactPropTypesSecret
);
if (error instanceof Error) {
return error;
Expand All @@ -351,7 +393,14 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
var checker = arrayOfTypeCheckers[i];
if (
checker(props, propName, componentName, location, propFullName) == null
checker(
props,
propName,
componentName,
location,
propFullName,
ReactPropTypesSecret
) == null
) {
return null;
}
Expand Down Expand Up @@ -401,7 +450,8 @@ function createShapeTypeChecker(shapeTypes) {
key,
componentName,
location,
`${propFullName}.${key}`
`${propFullName}.${key}`,
ReactPropTypesSecret
);
if (error) {
return error;
Expand Down
Loading