From 5dffbf27d09fe682e4ef20ea363f605bedc8c1c5 Mon Sep 17 00:00:00 2001 From: Hassan Usman <38628704+husseyexplores@users.noreply.github.com> Date: Fri, 15 Nov 2019 18:35:23 +0500 Subject: [PATCH] [fixed] Call parent.removeChild only if parent exists (#778) --- src/components/Modal.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/Modal.js b/src/components/Modal.js index 498f8467..0ef0b618 100644 --- a/src/components/Modal.js +++ b/src/components/Modal.js @@ -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 => {