Error boundries should not unmount composite components which were not mounted.

This commit is contained in:
jim
2016-02-04 17:10:18 -08:00
parent 220b4b6b50
commit 86305fba41
2 changed files with 39 additions and 1 deletions
@@ -79,6 +79,40 @@ describe('ReactErrorBoundaries', function() {
expect(EventPluginHub.putListener).toBeCalled();
});
it('correctly handles composite siblings', function() {
class ErrorBoundary extends React.Component {
constructor() {
super();
this.state = {error: false};
}
render() {
if (!this.state.error) {
return <div>{this.props.children}</div>;
}
return <div>Error has been caught</div>;
}
unstable_handleError() {
this.setState({error: true});
}
}
function Broken() {
throw new Error('Always broken.');
}
function Composite() {
return <div />;
}
var container = document.createElement('div');
ReactDOM.render(
<ErrorBoundary><Broken /><Composite /></ErrorBoundary>,
container
);
ReactDOM.unmountComponentAtNode(container);
});
it('catches errors from children', function() {
var log = [];
@@ -144,15 +178,16 @@ describe('ReactErrorBoundaries', function() {
var container = document.createElement('div');
ReactDOM.render(<Box />, container);
expect(container.textContent).toBe('Error: Please, do not render me.');
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'Box render',
'Inquisitive render',
'Angry render',
'Inquisitive ref null',
'Inquisitive componentWillUnmount',
'Angry componentWillUnmount',
'Box renderError',
'Box componentDidMount',
'Box componentWillUnmount',
]);
});
});
@@ -369,6 +369,9 @@ var ReactCompositeComponentMixin = {
* @internal
*/
unmountComponent: function() {
if (!this._renderedComponent) {
return;
}
var inst = this._instance;
if (inst.componentWillUnmount) {