Skip to content

Commit

Permalink
Merge pull request facebook#6677 from zpao/dont-warn-css-0-string
Browse files Browse the repository at this point in the history
Don't warn when style value is '0'
  • Loading branch information
zpao committed May 27, 2016
2 parents 0f4a4df + fa89cf5 commit 5c6f9d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ describe('ReactDOMComponent', function() {
expect(console.error.calls.count()).toBe(2);
});

it('should not warn for "0" as a unitless style value', function() {
spyOn(console, 'error');
var Component = React.createClass({
render: function() {
return <div style={{margin: '0'}} />;
},
});

ReactTestUtils.renderIntoDocument(<Component />);
expect(console.error.calls.length).toBe(0);
});

it('should warn nicely about NaN in style', function() {
spyOn(console, 'error');

Expand Down
6 changes: 4 additions & 2 deletions src/renderers/dom/shared/dangerousStyleValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ function dangerousStyleValue(name, value, component) {
}

var isNonNumeric = isNaN(value);
if (isNonNumeric || value === 0 || value === '0' ||
if (isNonNumeric || value === 0 ||
isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name]) {
return '' + value; // cast to string
}

if (typeof value === 'string') {
if (__DEV__) {
if (component) {
// Allow '0' to pass through without warning. 0 is already special and
// doesn't require units, so we don't need to warn about it.
if (component && value !== '0') {
var owner = component._currentElement._owner;
var ownerName = owner ? owner.getName() : null;
if (ownerName && !styleWarnings[ownerName]) {
Expand Down

0 comments on commit 5c6f9d3

Please sign in to comment.