From dcdc35fab69fa28a6cda7b3fe5dc904ccfbe5455 Mon Sep 17 00:00:00 2001 From: Charles Marsh Date: Wed, 13 Aug 2014 15:04:19 -0400 Subject: [PATCH] More informative error message for mergeObjectsWithNoDuplicateKeys --- src/core/ReactCompositeComponent.js | 7 ++++++- src/core/__tests__/ReactCompositeComponent-test.js | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/ReactCompositeComponent.js b/src/core/ReactCompositeComponent.js index 42a1dcb45b..01d8539ca3 100644 --- a/src/core/ReactCompositeComponent.js +++ b/src/core/ReactCompositeComponent.js @@ -592,7 +592,12 @@ function mergeObjectsWithNoDuplicateKeys(one, two) { invariant( one[key] === undefined, 'mergeObjectsWithNoDuplicateKeys(): ' + - 'Tried to merge two objects with the same key: %s', + 'Tried to merge two objects with the same key: `%s`. ' + + 'This conflict may be due to a mixin; in particular, you may be using ' + + 'a mixin with its own getDefaultProps() or getInitialState(). This ' + + 'could result in both the mixin and base component (or another mixin) ' + + 'returning an object (either from getDefaultProps() or ' + + 'getInitialState()) with the same key.', key ); one[key] = value; diff --git a/src/core/__tests__/ReactCompositeComponent-test.js b/src/core/__tests__/ReactCompositeComponent-test.js index abfedc5dee..2aabc6d4ab 100644 --- a/src/core/__tests__/ReactCompositeComponent-test.js +++ b/src/core/__tests__/ReactCompositeComponent-test.js @@ -688,7 +688,12 @@ describe('ReactCompositeComponent', function() { instance = ReactTestUtils.renderIntoDocument(instance); }).toThrow( 'Invariant Violation: mergeObjectsWithNoDuplicateKeys(): ' + - 'Tried to merge two objects with the same key: x' + 'Tried to merge two objects with the same key: `x`. ' + + 'This conflict may be due to a mixin; in particular, you may be using ' + + 'a mixin with its own getDefaultProps() or getInitialState(). This ' + + 'could result in both the mixin and base component (or another mixin) ' + + 'returning an object (either from getDefaultProps() or ' + + 'getInitialState()) with the same key.' ); });