mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #4588 from sebmarkbage/ownersforcontext
Add property key names + type of value to fragment warning
This commit is contained in:
@@ -83,13 +83,17 @@ if (__DEV__) {
|
||||
|
||||
var issuedWarnings = {};
|
||||
|
||||
var didWarnForFragment = function(fragment) {
|
||||
// We use the keys and the type of the value as a heuristic to dedupe the
|
||||
// warning to avoid spamming too much.
|
||||
var getFragmentKeyString = function(fragment) {
|
||||
var fragmentCacheKey = '';
|
||||
for (var key in fragment) {
|
||||
fragmentCacheKey += key + ':' + (typeof fragment[key]) + ',';
|
||||
}
|
||||
return fragmentCacheKey;
|
||||
};
|
||||
|
||||
var didWarnForFragment = function(fragmentCacheKey) {
|
||||
// We use the keys and the type of the value as a heuristic to dedupe the
|
||||
// warning to avoid spamming too much.
|
||||
var alreadyWarnedOnce = !!issuedWarnings[fragmentCacheKey];
|
||||
issuedWarnings[fragmentCacheKey] = true;
|
||||
return alreadyWarnedOnce;
|
||||
@@ -143,11 +147,13 @@ var ReactFragment = {
|
||||
if (__DEV__) {
|
||||
if (canWarnForReactFragment) {
|
||||
if (!fragment[fragmentKey]) {
|
||||
var fragmentKeys = getFragmentKeyString(fragment);
|
||||
warning(
|
||||
didWarnForFragment(fragment),
|
||||
didWarnForFragment(fragmentKeys),
|
||||
'Any use of a keyed object should be wrapped in ' +
|
||||
'React.addons.createFragment(object) before being passed as a ' +
|
||||
'child.'
|
||||
'child. {%s}',
|
||||
fragmentKeys
|
||||
);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ describe('ReactFragment', function() {
|
||||
expect(console.error.calls[0].args[0]).toContain(
|
||||
'Any use of a keyed object'
|
||||
);
|
||||
expect(console.error.calls[0].args[0]).toContain(
|
||||
'{x:object,y:object,}'
|
||||
);
|
||||
// Only warn once for the same set of children
|
||||
var sameChildren = {
|
||||
x: <span />,
|
||||
@@ -56,6 +59,9 @@ describe('ReactFragment', function() {
|
||||
expect(console.error.calls[0].args[0]).toContain(
|
||||
'Any use of a keyed object'
|
||||
);
|
||||
expect(console.error.calls[0].args[0]).toContain(
|
||||
'{x:object,y:object,z:object,}'
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if a plain object even if it is in an owner', function() {
|
||||
|
||||
Reference in New Issue
Block a user