Skip to content

Commit 62f0fbf

Browse files
committed
Revert "Revert "Warn if PropType function is called manually (facebook#7132)""
This reverts commit be71f76. In other words, now we again have the warning if you attempt to call PropTypes manually. It was removed in facebook#8066 but we shouldn't have done this since we still want to avoid people accidentally calling them in production (and even more so since now it would throw). Fixes facebook#8080.
1 parent d845084 commit 62f0fbf

File tree

4 files changed

+263
-8
lines changed

4 files changed

+263
-8
lines changed

src/isomorphic/classic/types/ReactPropTypes.js

+57-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
var ReactElement = require('ReactElement');
1515
var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
16+
var ReactPropTypesSecret = require('ReactPropTypesSecret');
1617

1718
var emptyFunction = require('emptyFunction');
1819
var getIteratorFn = require('getIteratorFn');
@@ -154,16 +155,42 @@ function PropTypeError(message) {
154155
PropTypeError.prototype = Error.prototype;
155156

156157
function createChainableTypeChecker(validate) {
158+
if (__DEV__) {
159+
var manualPropTypeCallCache = {};
160+
}
157161
function checkType(
158162
isRequired,
159163
props,
160164
propName,
161165
componentName,
162166
location,
163-
propFullName
167+
propFullName,
168+
secret
164169
) {
165170
componentName = componentName || ANONYMOUS;
166171
propFullName = propFullName || propName;
172+
if (__DEV__) {
173+
if (
174+
secret !== ReactPropTypesSecret &&
175+
typeof console !== 'undefined'
176+
) {
177+
var cacheKey = `${componentName}:${propName}`;
178+
if (!manualPropTypeCallCache[cacheKey]) {
179+
warning(
180+
false,
181+
'You are manually calling a React.PropTypes validation ' +
182+
'function for the `%s` prop on `%s`. This is deprecated ' +
183+
'and will not work in production with the next major version. ' +
184+
'You may be seeing this warning due to a third-party PropTypes ' +
185+
'library. See https://fb.me/react-warning-dont-call-proptypes ' +
186+
'for details.',
187+
propFullName,
188+
componentName
189+
);
190+
manualPropTypeCallCache[cacheKey] = true;
191+
}
192+
}
193+
}
167194
if (props[propName] == null) {
168195
var locationName = ReactPropTypeLocationNames[location];
169196
if (isRequired) {
@@ -180,7 +207,13 @@ function createChainableTypeChecker(validate) {
180207
}
181208
return null;
182209
} else {
183-
return validate(props, propName, componentName, location, propFullName);
210+
return validate(
211+
props,
212+
propName,
213+
componentName,
214+
location,
215+
propFullName,
216+
);
184217
}
185218
}
186219

@@ -191,7 +224,14 @@ function createChainableTypeChecker(validate) {
191224
}
192225

193226
function createPrimitiveTypeChecker(expectedType) {
194-
function validate(props, propName, componentName, location, propFullName) {
227+
function validate(
228+
props,
229+
propName,
230+
componentName,
231+
location,
232+
propFullName,
233+
secret
234+
) {
195235
var propValue = props[propName];
196236
var propType = getPropType(propValue);
197237
if (propType !== expectedType) {
@@ -238,7 +278,8 @@ function createArrayOfTypeChecker(typeChecker) {
238278
i,
239279
componentName,
240280
location,
241-
`${propFullName}[${i}]`
281+
`${propFullName}[${i}]`,
282+
ReactPropTypesSecret
242283
);
243284
if (error instanceof Error) {
244285
return error;
@@ -329,7 +370,8 @@ function createObjectOfTypeChecker(typeChecker) {
329370
key,
330371
componentName,
331372
location,
332-
`${propFullName}.${key}`
373+
`${propFullName}.${key}`,
374+
ReactPropTypesSecret
333375
);
334376
if (error instanceof Error) {
335377
return error;
@@ -351,7 +393,14 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
351393
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
352394
var checker = arrayOfTypeCheckers[i];
353395
if (
354-
checker(props, propName, componentName, location, propFullName) == null
396+
checker(
397+
props,
398+
propName,
399+
componentName,
400+
location,
401+
propFullName,
402+
ReactPropTypesSecret
403+
) == null
355404
) {
356405
return null;
357406
}
@@ -401,7 +450,8 @@ function createShapeTypeChecker(shapeTypes) {
401450
key,
402451
componentName,
403452
location,
404-
`${propFullName}.${key}`
453+
`${propFullName}.${key}`,
454+
ReactPropTypesSecret
405455
);
406456
if (error) {
407457
return error;

0 commit comments

Comments
 (0)