From be78a418922f1cbdee15f85a8a80121818da6be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Mon, 2 May 2016 11:22:55 -0700 Subject: [PATCH 1/2] Revert "Merge pull request #6458 from mondaychen/master" This reverts commit 25481083b0138fe052fcd00c591dc5e10e0a64d6, reversing changes made to 09022b165f7fdec4a1aaf6475936629aab76e4a9. --- src/renderers/dom/shared/dangerousStyleValue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/dom/shared/dangerousStyleValue.js b/src/renderers/dom/shared/dangerousStyleValue.js index f0ed355178eeb..8aa2e49607fa1 100644 --- a/src/renderers/dom/shared/dangerousStyleValue.js +++ b/src/renderers/dom/shared/dangerousStyleValue.js @@ -44,7 +44,7 @@ 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 } From fa89cf53f2803fd51e67e592ffde3c2fbdbf20a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Mon, 2 May 2016 11:39:56 -0700 Subject: [PATCH 2/2] Don't warn when style value is '0' --- .../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 703f3cab76804..5957592463616 100644 --- a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js +++ b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js @@ -190,6 +190,18 @@ describe('ReactDOMComponent', function() { expect(console.error.calls.length).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]) {