More informative error message for mergeObjectsWithNoDuplicateKeys
Charles Marsh committed
Aug 13, 2014 at 15:04 UTC
dcdc35fab69fa28a6cda7b3fe5dc904ccfbe5455
2 files changed
+12
-2
src/core/ReactCompositeComponent.js
+6
-1
@@ -592,7 +592,12 @@ function mergeObjectsWithNoDuplicateKeys(one, two) {
592
invariant(
593
one[key] === undefined,
594
'mergeObjectsWithNoDuplicateKeys(): ' +
595
- 'Tried to merge two objects with the same key: %s',
595
+ 'Tried to merge two objects with the same key: `%s`. ' +
596
+ 'This conflict may be due to a mixin; in particular, you may be using ' +
597
+ 'a mixin with its own getDefaultProps() or getInitialState(). This ' +
598
+ 'could result in both the mixin and base component (or another mixin) ' +
599
+ 'returning an object (either from getDefaultProps() or ' +
600
+ 'getInitialState()) with the same key.',
601
key
602
);
603
one[key] = value;
src/core/__tests__/ReactCompositeComponent-test.js
+6
-1
@@ -688,7 +688,12 @@ describe('ReactCompositeComponent', function() {
688
instance = ReactTestUtils.renderIntoDocument(instance);
689
}).toThrow(
690
'Invariant Violation: mergeObjectsWithNoDuplicateKeys(): ' +
691
- 'Tried to merge two objects with the same key: x'
691
+ 'Tried to merge two objects with the same key: `x`. ' +
692
+ 'This conflict may be due to a mixin; in particular, you may be using ' +
693
+ 'a mixin with its own getDefaultProps() or getInitialState(). This ' +
694
+ 'could result in both the mixin and base component (or another mixin) ' +
695
+ 'returning an object (either from getDefaultProps() or ' +
696
+ 'getInitialState()) with the same key.'
697
);
698
});
699