From 0f34b19f0bb6c115a7be3de39f28864292b5da45 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Fri, 22 Jul 2016 15:10:45 +0300 Subject: [PATCH] Better debugging of `Expected props argument to be a plain object` --- src/isomorphic/classic/element/ReactElement.js | 18 ++++++++++-------- .../element/__tests__/ReactElement-test.js | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/isomorphic/classic/element/ReactElement.js b/src/isomorphic/classic/element/ReactElement.js index 710bcaa532546..68df337dc37d1 100644 --- a/src/isomorphic/classic/element/ReactElement.js +++ b/src/isomorphic/classic/element/ReactElement.js @@ -167,8 +167,8 @@ ReactElement.createElement = function(type, config, children) { /* eslint-disable no-proto */ config.__proto__ == null || config.__proto__ === Object.prototype, /* eslint-enable no-proto */ - 'React.createElement(...): Expected props argument to be a plain object. ' + - 'Properties defined in its prototype chain will be ignored.' + 'React.createElement(...): Expected props argument of ' + displayName(type) + + ' to be a plain object. Properties defined in its prototype chain will be ignored.' ); } @@ -213,10 +213,6 @@ ReactElement.createElement = function(type, config, children) { } } if (__DEV__) { - var displayName = typeof type === 'function' ? - (type.displayName || type.name || 'Unknown') : - type; - // Create dummy `key` and `ref` property to `props` to warn users against its use var warnAboutAccessingKey = function() { if (!specialPropKeyWarningShown) { @@ -227,7 +223,7 @@ ReactElement.createElement = function(type, config, children) { 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', - displayName + displayName(type) ); } return undefined; @@ -243,7 +239,7 @@ ReactElement.createElement = function(type, config, children) { 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', - displayName + displayName(type) ); } return undefined; @@ -408,4 +404,10 @@ ReactElement.isValidElement = function(object) { ReactElement.REACT_ELEMENT_TYPE = REACT_ELEMENT_TYPE; +function displayName(type) { + return typeof type === 'function' ? + (type.displayName || type.name || 'ReactElement') : + type; +} + module.exports = ReactElement; diff --git a/src/isomorphic/classic/element/__tests__/ReactElement-test.js b/src/isomorphic/classic/element/__tests__/ReactElement-test.js index 353989ad6b089..008eeba0535f2 100644 --- a/src/isomorphic/classic/element/__tests__/ReactElement-test.js +++ b/src/isomorphic/classic/element/__tests__/ReactElement-test.js @@ -195,7 +195,8 @@ describe('ReactElement', function() { React.createElement('div', Object.create({foo: 1})); expect(console.error.calls.count()).toBe(1); expect(console.error.calls.argsFor(0)[0]).toContain( - 'React.createElement(...): Expected props argument to be a plain object. ' + + 'React.createElement(...): Expected props argument of div ' + + 'to be a plain object. ' + 'Properties defined in its prototype chain will be ignored.' ); });