Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __tests__/PropTypesDevelopmentReact15.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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