Skip to content

Clearer warning when replacing React-rendered children with a new root component #2045

@sophiebits

Description

@sophiebits

Suppose you have:

var TaskHeader = React.createClass({
    render: function() {
        return <div className="task-header-mid-container">
            <img />
            <h2>I'm a task!</h2>
        </div>;
    }
});

React.renderComponent(<TaskHeader />, $(".task-header-container")[0]);

and then you intend to run

React.renderComponent(<ADifferentTaskHeader />, $(".task-header-container")[0]);

to replace the header but accidentally run

React.renderComponent(<ADifferentTaskHeader />, $(".task-header-mid-container")[0]);

instead.

You should get an error or warning because you're blowing away the React-rendered contents of .task-header-mid-container, but none is given. You actually get the server-rendering checksum warning, but that's more confusing than anything and we should have an explicit warning for this, much like the one you get when calling setProps on a non-root component.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions