Skip to content

Commit

Permalink
Fix for style not always reset when set to null
Browse files Browse the repository at this point in the history
When the style property existed, but was set to null, `this._previousStyleCopy`
was not set back to `null` causing an old value to persist. This broke setting
the style to `null` the next time.

Fixes facebook#3606.
  • Loading branch information
kassens committed Apr 7, 2015
1 parent ddbbaa9 commit eda9ec5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/browser/ui/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ ReactDOMComponent.Mixin = {
if (propKey === STYLE) {
if (nextProp) {
nextProp = this._previousStyleCopy = assign({}, nextProp);
} else {
this._previousStyleCopy = null;
}
if (lastProp) {
// Unset styles on `lastProp` but not on `nextProp`.
Expand Down
21 changes: 21 additions & 0 deletions src/browser/ui/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ describe('ReactDOMComponent', function() {
expect(stubStyle.display).toEqual('block');
});

it("should update styles if updated to null multiple times", function() {
var styles = null;
var container = document.createElement('div');
React.render(<div style={styles} />, container);

styles = {display: 'block'};
var stubStyle = container.firstChild.style;

React.render(<div style={styles} />, container);
expect(stubStyle.display).toEqual('block');

React.render(<div style={null} />, container);
expect(stubStyle.display).toEqual('');

React.render(<div style={styles} />, container);
expect(stubStyle.display).toEqual('block');

React.render(<div style={null} />, container);
expect(stubStyle.display).toEqual('');
});

it("should remove attributes", function() {
var container = document.createElement('div');
React.render(<img height='17' />, container);
Expand Down

0 comments on commit eda9ec5

Please sign in to comment.