diff --git a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js index f55475b8c2dcc..9dfea6dee139b 100644 --- a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js +++ b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js @@ -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
; + }, + }); + + ReactTestUtils.renderIntoDocument(); + expect(console.error.calls.length).toBe(0); + }); + it('should warn nicely about NaN in style', function() { spyOn(console, 'error'); diff --git a/src/renderers/dom/shared/dangerousStyleValue.js b/src/renderers/dom/shared/dangerousStyleValue.js index f0ed355178eeb..8b5424cc8eed7 100644 --- a/src/renderers/dom/shared/dangerousStyleValue.js +++ b/src/renderers/dom/shared/dangerousStyleValue.js @@ -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]) {