Use warning module for context warning instead of invoking console.warn and monitorCodeUse directly. Depends on https://phabricator.fb.com/D1695279
Jim committed
Nov 20, 2014 at 14:23 UTC
9f7901fe1da0968ed70b5c6ef360c66e89536e1f
2 files changed
+13
-15
src/core/ReactCompositeComponent.js
+10
-13
@@ -597,19 +597,16 @@ var ReactCompositeComponentMixin = assign({},
597
_warnIfContextsDiffer: function(ownerBasedContext, parentBasedContext) {
598
var ownerKeys = Object.keys(ownerBasedContext).sort();
599
var parentKeys = Object.keys(parentBasedContext).sort();
600
- if (ownerKeys.length != parentKeys.length || ownerKeys.toString() != parentKeys.toString()) {
601
- var message = ("owner based context (keys: " +
602
- Object.keys(ownerBasedContext) + ") does not equal parent based" +
603
- " context (keys: "+Object.keys(parentBasedContext)+")" +
604
- " while mounting " +
605
- (this._instance.constructor.displayName || 'ReactCompositeComponent'));
606
- console.warn(message);
607
- monitorCodeUse('contexts_differ', {
608
- ownerBasedKeys: Object.keys(ownerBasedContext),
609
- parentBasedKeys: Object.keys(parentBasedContext),
610
- mounting: (this._instance.constructor.displayName || 'ReactCompositeComponent')
611
- });
612
- }
600
+ warning(
601
+ ownerKeys.length === parentKeys.length &&
602
+ ownerKeys.toString() === parentKeys.toString(),
603
+ 'owner based context (keys: %s) does not equal parent based' +
604
+ ' context (keys: %s) while mounting %s' +
605
+ ' (see: http://fb.me/react-context-by-parent)',
606
+ Object.keys(ownerBasedContext),
607
+ Object.keys(parentBasedContext),
608
+ (this._instance.constructor.displayName || 'ReactCompositeComponent')
609
+ );
610
},
611
612
/**
src/core/__tests__/ReactCompositeComponent-test.js
+3
-2
@@ -1026,8 +1026,9 @@ describe('ReactCompositeComponent', function() {
1026
1027
expect(console.warn.mock.calls.length).toBe(2);
1028
expect(console.warn.mock.calls[1][0]).toBe(
1029
- 'owner based context (keys: foo) does not equal parent based ' +
1030
- 'context (keys: ) while mounting ReactCompositeComponent'
1029
+ 'Warning: owner based context (keys: foo) does not equal parent based ' +
1030
+ 'context (keys: ) while mounting ReactCompositeComponent ' +
1031
+ '(see: http://fb.me/react-context-by-parent)'
1032
);
1033
1034
});