Skip to content

Commit

Permalink
Merge pull request #26 from reactjs/limit-warning-count
Browse files Browse the repository at this point in the history
Limit manual PropTypes call warning count
  • Loading branch information
gaearon committed Apr 12, 2017
2 parents 6a5fc72 + e1d51dd commit b06161d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions __tests__/PropTypesDevelopmentReact15.js
Expand Up @@ -93,6 +93,7 @@ function typeCheckPass(declaration, value) {
}

function expectWarningInDevelopment(declaration, value) {
resetWarningCache();
var props = {testProp: value};
var propName = 'testProp' + Math.random().toString();
var componentName = 'testComponent' + Math.random().toString();
Expand Down
8 changes: 7 additions & 1 deletion factoryWithTypeCheckers.js
Expand Up @@ -148,6 +148,7 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
function createChainableTypeChecker(validate) {
if (process.env.NODE_ENV !== 'production') {
var manualPropTypeCallCache = {};
var manualPropTypeWarningCount = 0;
}
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
componentName = componentName || ANONYMOUS;
Expand All @@ -165,7 +166,11 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
} else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
// Old behavior for people using React.PropTypes
var cacheKey = componentName + ':' + propName;
if (!manualPropTypeCallCache[cacheKey]) {
if (
!manualPropTypeCallCache[cacheKey] &&
// Avoid spamming the console because they are often not actionable except for lib authors
manualPropTypeWarningCount < 3
) {
warning(
false,
'You are manually calling a React.PropTypes validation ' +
Expand All @@ -177,6 +182,7 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
componentName
);
manualPropTypeCallCache[cacheKey] = true;
manualPropTypeWarningCount++;
}
}
}
Expand Down

0 comments on commit b06161d

Please sign in to comment.