Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Uncaught [NotFoundError: The node to be removed is not a child of this node.] #820

Closed
dremlin2000 opened this issue Jul 31, 2020 · 1 comment · Fixed by #821
Closed

Comments

@dremlin2000
Copy link

dremlin2000 commented Jul 31, 2020

Summary:

This issue comes up when I run react testing library tests. It seems that the parent component removes react-modal I am assuming on unmount event what leads to Error: Uncaught [NotFoundError: The node to be removed is not a child of this node.]. . This issue is very similar to already raised one #769 but the corresponding PR #778 does not actually address the original issue.

I found code which causes this issue

const parent = getParentElement(this.props.parentSelector);
if (parent) {
parent.removeChild(this.node);
} else {
and fix should pretty simple like

    if (parent && parent.contains(this.node)) {
      parent.removeChild(this.node);
    }

I will appreciate if someone comes up with a workaround.

@dremlin2000
Copy link
Author

dremlin2000 commented Aug 1, 2020

If someone else experiences the similar problem then the following workaround should fix it but the warning message
React-Modal: "parentSelector" prop did not returned any DOM element. Make sure that the parent element is unmounted to avoid any memory leaks. will be written in console.

export default function ReactModal() {
    let unmounted = false
    
    useEffect(() => () => unmounted = true)

    return (
        <Modal parentSelector={() => unmounted ? undefined : document.body}>
            <h1>Hello!!!</h1>
        </Modal>
    )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant