Don't mutate .props.style in ReactDOMComponent
We currently make a copy of .style because we support mutating the style object in place. Instead of storing it back on props, store it separately on the component instance so that we don't mutate props anywhere. This is gross but should all be cleaned up after #2008 is resolved. Test Plan: jest
Ben Alpert committed
Nov 15, 2014 at 15:29 UTC
f391b7b3ca604f37f44193061f816baa0b830b26
1 file changed
+7
-4
src/browser/ui/ReactDOMComponent.js
+7
-4
@@ -174,6 +174,7 @@ ReactDOMComponent.Mixin = {
174
mountDepth
175
);
176
assertValidProps(this.props);
177
+ this._previousStyleCopy = null;
178
var closeTag = omittedCloseTags[this._tag] ? '' : '</' + this._tag + '>';
179
return (
180
this._createOpenTagMarkupAndPutListeners(transaction) +
@@ -212,7 +213,7 @@ ReactDOMComponent.Mixin = {
213
} else {
214
if (propKey === STYLE) {
215
if (propValue) {
215
- propValue = props.style = assign({}, props.style);
216
+ propValue = this._previousStyleCopy = assign({}, props.style);
217
}
218
propValue = CSSPropertyOperations.createMarkupForStyles(propValue);
219
}
@@ -347,7 +348,7 @@ ReactDOMComponent.Mixin = {
348
continue;
349
}
350
if (propKey === STYLE) {
350
- var lastStyle = lastProps[propKey];
351
+ var lastStyle = this._previousStyleCopy;
352
for (styleName in lastStyle) {
353
if (lastStyle.hasOwnProperty(styleName)) {
354
styleUpdates = styleUpdates || {};
@@ -367,13 +368,15 @@ ReactDOMComponent.Mixin = {
368
}
369
for (propKey in nextProps) {
370
var nextProp = nextProps[propKey];
370
- var lastProp = lastProps[propKey];
371
+ var lastProp = propKey === STYLE ?
372
+ this._previousStyleCopy :
373
+ lastProps[propKey];
374
if (!nextProps.hasOwnProperty(propKey) || nextProp === lastProp) {
375
continue;
376
}
377
if (propKey === STYLE) {
378
if (nextProp) {
376
- nextProp = nextProps.style = assign({}, nextProp);
379
+ nextProp = this._previousStyleCopy = assign({}, nextProp);
380
}
381
if (lastProp) {
382
// Unset styles on `lastProp` but not on `nextProp`.