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

Limit manual PropTypes call warning count #26

Merged
merged 1 commit into from Apr 12, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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