Skip to content

Commit 3e07113

Browse files
husseyexploresprogrammer4web
authored andcommitted
[fixed] Call parent.removeChild only if parent exists (reactjs#778)
1 parent 461ace3 commit 3e07113

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/components/Modal.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,16 @@ class Modal extends Component {
174174
removePortal = () => {
175175
!isReact16 && ReactDOM.unmountComponentAtNode(this.node);
176176
const parent = getParentElement(this.props.parentSelector);
177-
parent.removeChild(this.node);
177+
if (parent) {
178+
parent.removeChild(this.node);
179+
} else {
180+
// eslint-disable-next-line no-console
181+
console.warn(
182+
'React-Modal: "parentSelector" prop did not returned any DOM ' +
183+
"element. Make sure that the parent element is unmounted to " +
184+
"avoid any memory leaks."
185+
);
186+
}
178187
};
179188

180189
portalRef = ref => {

0 commit comments

Comments
 (0)