Skip to content

Incorrect update of style attribute when style prop transitions from object -> null -> object #3409

@robertknight

Description

@robertknight

The style attribute for a DOM node is incorrectly updated when the corresponding props key transitions from being an object to null to an object again over a series of updates.

From a brief investigation it appears that this is happening because this._previousStyleCopy is not cleared when the style attribute is removed from props so in the third render in the example below, React compares the style value from the first render with the style value from the third render.

Looking at f391b7b I'm unsure whether the style copy described there is still needed?

var jsdom = require('jsdom');
var react = require('react');

var App = react.createFactory(react.createClass({
    render: function() {
        var style = this.props.useRedText ? {color: 'red'} : null;
        return react.DOM.div({style: style}, 'test');
    }
}));

jsdom.env({
    html: '<div id="app"></div>',
    done: function(errors, window) {
        global.window = window;
        global.document = window.document;

        var appElement = document.getElementById('app');
        react.render(App({useRedText: true}), appElement);
        react.render(App({useRedText: false}), appElement);
        react.render(App({useRedText: true}), appElement);

        // expected output: <div style="color: 'red'" ...>
        // actual output: <div style="" ...>
        console.log(appElement.innerHTML);
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions