Dedupe warnings in validateDOMNesting
Fixes #3921.
Ben Alpert committed
May 22, 2015 at 00:46 UTC
08b55e1c4fba0fcfd0df6e4c513f3c1b8e227527
2 files changed
+10
-1
src/renderers/dom/client/validateDOMNesting.js
+9
@@ -319,6 +319,8 @@ if (__DEV__) {
319
return stack;
320
};
321
322
+ var didWarn = {};
323
+
324
validateDOMNesting = function(childTag, childInstance, ancestorInfo) {
325
ancestorInfo = ancestorInfo || emptyAncestorInfo;
326
var parentInfo = ancestorInfo.parentTag;
@@ -374,6 +376,13 @@ if (__DEV__) {
376
childTag
377
).join(' > ');
378
379
+ var warnKey =
380
+ !!invalidParent + '|' + childTag + '|' + ancestorTag + '|' + ownerInfo;
381
+ if (didWarn[warnKey]) {
382
+ return;
383
+ }
384
+ didWarn[warnKey] = true;
385
+
386
if (invalidParent) {
387
var info = '';
388
if (ancestorTag === 'table' && childTag === 'tr') {
src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
+1
-1
@@ -733,7 +733,7 @@ describe('ReactDOMComponent', function() {
733
734
it('warns on invalid nesting', () => {
735
spyOn(console, 'error');
736
- ReactTestUtils.renderIntoDocument(<div><tr /></div>);
736
+ ReactTestUtils.renderIntoDocument(<div><tr /><tr /></div>);
737
738
expect(console.error.calls.length).toBe(1);
739
expect(console.error.calls[0].args[0]).toBe(