@samitouri / QOS-React-2 / commits / eda9ec53b5

Fix for style not always reset when set to null

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 #3606.

Jan Kassens committed Apr 7, 2015 at 11:44 UTC eda9ec53b550194336eb19d8dd9b5d752ff50043
2 files changed +23
src/browser/ui/ReactDOMComponent.js
+2
@@ -442,6 +442,8 @@ ReactDOMComponent.Mixin = {
442 if (propKey === STYLE) {
443 if (nextProp) {
444 nextProp = this._previousStyleCopy = assign({}, nextProp);
445 + } else {
446 + this._previousStyleCopy = null;
447 }
448 if (lastProp) {
449 // Unset styles on `lastProp` but not on `nextProp`.
src/browser/ui/__tests__/ReactDOMComponent-test.js
+21
@@ -109,6 +109,27 @@ describe('ReactDOMComponent', function() {
109 expect(stubStyle.display).toEqual('block');
110 });
111
112 + it("should update styles if updated to null multiple times", function() {
113 + var styles = null;
114 + var container = document.createElement('div');
115 + React.render(<div style={styles} />, container);
116 +
117 + styles = {display: 'block'};
118 + var stubStyle = container.firstChild.style;
119 +
120 + React.render(<div style={styles} />, container);
121 + expect(stubStyle.display).toEqual('block');
122 +
123 + React.render(<div style={null} />, container);
124 + expect(stubStyle.display).toEqual('');
125 +
126 + React.render(<div style={styles} />, container);
127 + expect(stubStyle.display).toEqual('block');
128 +
129 + React.render(<div style={null} />, container);
130 + expect(stubStyle.display).toEqual('');
131 + });
132 +
133 it("should remove attributes", function() {
134 var container = document.createElement('div');
135 React.render(<img height='17' />, container);