Skip to content

Commit

Permalink
[fixed] Call parent.removeChild only if parent exists (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
husseyexplores authored and diasbruno committed Nov 15, 2019
1 parent 684d3b8 commit 5dffbf2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,16 @@ class Modal extends Component {
removePortal = () => {
!isReact16 && ReactDOM.unmountComponentAtNode(this.node);
const parent = getParentElement(this.props.parentSelector);
parent.removeChild(this.node);
if (parent) {
parent.removeChild(this.node);
} else {
// eslint-disable-next-line no-console
console.warn(
'React-Modal: "parentSelector" prop did not returned any DOM ' +
"element. Make sure that the parent element is unmounted to " +
"avoid any memory leaks."
);
}
};

portalRef = ref => {
Expand Down

0 comments on commit 5dffbf2

Please sign in to comment.