Fix incorrect update of style when props.style transitions from null to non-null
ReactDOMComponent maintains a copy of the previous style object to support in-place mutations of props.style. This cached object was not cleared when the style property was removed in a props update. Fixes #3409
Robert Knight committed
Mar 13, 2015 at 22:16 UTC
ee86942d77a2b835ce227bcc7e2287b6ce226d87
2 files changed
+12
src/browser/ui/ReactDOMComponent.js
+1
@@ -367,6 +367,7 @@ ReactDOMComponent.Mixin = {
367
styleUpdates[styleName] = '';
368
}
369
}
370
+ this._previousStyleCopy = null;
371
} else if (registrationNameModules.hasOwnProperty(propKey)) {
372
if (lastProps[propKey]) {
373
// Only call deleteListener if there was a listener previously or
src/browser/ui/__tests__/ReactDOMComponent-test.js
+11
@@ -152,6 +152,17 @@ describe('ReactDOMComponent', function() {
152
expect(stubStyle.color).toEqual('');
153
});
154
155
+ it("should update styles when 'style' changes from null to object", function() {
156
+ var container = document.createElement('div');
157
+ var styles = {color: 'red'};
158
+ React.render(<div style={styles} />, container);
159
+ React.render(<div />, container);
160
+ React.render(<div style={styles} />, container);
161
+
162
+ var stubStyle = container.firstChild.style;
163
+ expect(stubStyle.color).toEqual('red');
164
+ });
165
+
166
it("should empty element when removing innerHTML", function() {
167
var container = document.createElement('div');
168
React.render(<div dangerouslySetInnerHTML={{__html: ':)'}} />, container);