Don't warn when style value is '0'
Paul O’Shannessy committed
May 2, 2016 at 11:39 UTC
fa89cf53f2803fd51e67e592ffde3c2fbdbf20a0
2 files changed
+15
-1
src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
+12
@@ -190,6 +190,18 @@ describe('ReactDOMComponent', function() {
190
expect(console.error.calls.length).toBe(2);
191
});
192
193
+ it('should not warn for "0" as a unitless style value', function() {
194
+ spyOn(console, 'error');
195
+ var Component = React.createClass({
196
+ render: function() {
197
+ return <div style={{margin: '0'}} />;
198
+ },
199
+ });
200
+
201
+ ReactTestUtils.renderIntoDocument(<Component />);
202
+ expect(console.error.calls.length).toBe(0);
203
+ });
204
+
205
it('should warn nicely about NaN in style', function() {
206
spyOn(console, 'error');
207
src/renderers/dom/shared/dangerousStyleValue.js
+3
-1
@@ -51,7 +51,9 @@ function dangerousStyleValue(name, value, component) {
51
52
if (typeof value === 'string') {
53
if (__DEV__) {
54
- if (component) {
54
+ // Allow '0' to pass through without warning. 0 is already special and
55
+ // doesn't require units, so we don't need to warn about it.
56
+ if (component && value !== '0') {
57
var owner = component._currentElement._owner;
58
var ownerName = owner ? owner.getName() : null;
59
if (ownerName && !styleWarnings[ownerName]) {