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
This commit is contained in:
Robert Knight
2015-03-13 22:16:19 +00:00
parent 228c00b813
commit ee86942d77
2 changed files with 12 additions and 0 deletions
+1
View File
@@ -367,6 +367,7 @@ ReactDOMComponent.Mixin = {
styleUpdates[styleName] = '';
}
}
this._previousStyleCopy = null;
} else if (registrationNameModules.hasOwnProperty(propKey)) {
if (lastProps[propKey]) {
// Only call deleteListener if there was a listener previously or
@@ -152,6 +152,17 @@ describe('ReactDOMComponent', function() {
expect(stubStyle.color).toEqual('');
});
it("should update styles when 'style' changes from null to object", function() {
var container = document.createElement('div');
var styles = {color: 'red'};
React.render(<div style={styles} />, container);
React.render(<div />, container);
React.render(<div style={styles} />, container);
var stubStyle = container.firstChild.style;
expect(stubStyle.color).toEqual('red');
});
it("should empty element when removing innerHTML", function() {
var container = document.createElement('div');
React.render(<div dangerouslySetInnerHTML={{__html: ':)'}} />, container);