From 188156005526dcd8e7857623f849340012d5c7b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Thu, 26 May 2016 20:05:32 -0700 Subject: [PATCH] Merge pull request #6677 from zpao/dont-warn-css-0-string Don't warn when style value is '0' (cherry picked from commit 5c6f9d31bdec63021f6ae7b651dc5af71281a487) --- .../dom/shared/__tests__/ReactDOMComponent-test.js | 12 ++++++++++++ src/renderers/dom/shared/dangerousStyleValue.js | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js index 9d18c4e75a493..cfda7222faf10 100644 --- a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js +++ b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js @@ -203,6 +203,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 8aa2e49607fa1..8b5424cc8eed7 100644 --- a/src/renderers/dom/shared/dangerousStyleValue.js +++ b/src/renderers/dom/shared/dangerousStyleValue.js @@ -51,7 +51,9 @@ function dangerousStyleValue(name, value, component) { 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]) {