Skip to content

Commit

Permalink
Improve warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
pluma committed Oct 14, 2015
1 parent 8502374 commit 999b70a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
10 changes: 6 additions & 4 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ describe('ReactDOMComponent', function() {
ReactDOM.render(<One inline={false} />, div);
expect(console.error.calls.length).toBe(1);
expect(console.error.argsForCall[0][0]).toBe(
'Warning: `One` passed a numeric string value for CSS property `fontSize` ' +
'which will be treated as a unitless number.'
'Warning: a `div` tag (owner: `One`) was passed a numeric string value ' +
'for CSS property `fontSize` (value: `1`) which will be treated ' +
'as a unitless number in a future version of React.'
);

// Don't warn again for the same component
Expand All @@ -176,8 +177,9 @@ describe('ReactDOMComponent', function() {
ReactDOM.render(<Two />, div);
expect(console.error.calls.length).toBe(2);
expect(console.error.argsForCall[1][0]).toBe(
'Warning: `Two` passed a numeric string value for CSS property `fontSize` ' +
'which will be treated as a unitless number.'
'Warning: a `div` tag (owner: `Two`) was passed a numeric string value ' +
'for CSS property `fontSize` (value: `1`) which will be treated ' +
'as a unitless number in a future version of React.'
);

// Really don't warn again for the same component
Expand Down
29 changes: 19 additions & 10 deletions src/renderers/dom/shared/dangerousStyleValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,28 @@ function dangerousStyleValue(name, value, component) {
if (__DEV__) {
if (component) {
var owner = component._currentElement._owner;
var componentName = owner ? owner.getName() : component._currentElement.type;
if (!styleWarnings[componentName]) {
styleWarnings[componentName] = {};
var ownerName = owner ? owner.getName() : null;
if (ownerName && !styleWarnings[ownerName]) {
styleWarnings[ownerName] = {};
}
var warnings = styleWarnings[componentName];
if (!warnings[name]) {
warnings[name] = true;
var warned = false;
if (ownerName) {
var warnings = styleWarnings[ownerName];
warned = warnings[name]
if (!warned) {
warnings[name] = true;
}
}
if (!warned) {
warning(
false,
'`%s` passed a numeric string value for CSS property `%s` ' +
'which will be treated as a unitless number.',
componentName,
name
'a `%s` tag (owner: `%s`) was passed a numeric string value ' +
'for CSS property `%s` (value: `%s`) which will be treated ' +
'as a unitless number in a future version of React.',
component._currentElement.type,
ownerName || 'unknown',
name,
value
);
}
}
Expand Down

0 comments on commit 999b70a

Please sign in to comment.