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'
(cherry picked from commit 5c6f9d3)
  • Loading branch information
zpao committed Jun 8, 2016
1 parent 9f5c5d3 commit 1881560
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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 @@ -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 <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
4 changes: 3 additions & 1 deletion src/renderers/dom/shared/dangerousStyleValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit 1881560

Please sign in to comment.