Skip to content

Commit

Permalink
Merge b9a3415 into ba2fe90
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Shustov committed Feb 19, 2017
2 parents ba2fe90 + b9a3415 commit 411543c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export default class Modal extends Component {
const parent = getParentElement(this.props.parentSelector);
parent.appendChild(this.node);
this.renderPortal(this.props);

this.mounted = true;
}

componentWillReceiveProps (newProps) {
Expand All @@ -101,6 +103,8 @@ export default class Modal extends Component {
}

componentWillUnmount () {
if (!this.mounted) return;

if (this.props.ariaHideApp) {
ariaAppHider.show(this.props.appElement);
}
Expand Down
35 changes: 34 additions & 1 deletion specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
react/no-render-return-value: "warn"
*/
import TestUtils from 'react-addons-test-utils';
import React from 'react';
import React, { Component } from 'react';
import sinon from 'sinon';
import expect from 'expect';
import ReactDOM from 'react-dom';
Expand Down Expand Up @@ -519,4 +519,37 @@ describe('Modal', () => {
done();
}, closeTimeoutMS);
});

it('shouldn\'t throw if forcibly unmounted during mounting', () => {
/* eslint-disable camelcase, react/prop-types */
class Wrapper extends Component {
constructor (props) {
super(props);
this.state = { error: false };
}
unstable_handleError () {
this.setState({ error: true });
}
render () {
return this.state.error ? null : <div>{ this.props.children }</div>;
}
}
/* eslint-enable camelcase, react/prop-types */

const Throw = () => { throw new Error('reason'); };
const TestCase = () => (
<Wrapper>
<Modal />
<Throw />
</Wrapper>
);

const currentDiv = document.createElement('div');
document.body.appendChild(currentDiv);

const mount = () => ReactDOM.render(<TestCase />, currentDiv);
expect(mount).toNotThrow();

document.body.removeChild(currentDiv);
});
});

0 comments on commit 411543c

Please sign in to comment.