-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Warn if using React.unmountComponentAtNode on a different React instance's tree. #7456
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@ventuno could you add tests for this as well to verify it works? Thanks! |
Am I misunderstanding this or is the warning really confusing? It's not about unmounting something that "was rendered by another React instance", but trying to unmount something that isn't a React root (in this case, a React sub-tree). Right? |
@syranide looking at #3787 that does seem to be the goal. From @spicyj in the google groups thread:
|
Indeed, the goal of this PR is to show a warning whenever a react node is being unmounted by a different React instance than the one that has originally rendered it. |
* @return {boolean} True if the DOM is a valid DOM node. | ||
* @internal | ||
*/ | ||
function isNodeElement(node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call this isValidContainer?
Thanks for sending this in! Looks good except a couple nits inline. Mind updating? |
Thanks! |
As #3819 has been closed, I tried to provide a fix for #3787.
Node.ELEMENT_NODE
,Node.DOCUMENT_NODE
orNode.DOCUMENT_FRAGMENT_NODE
, see [1]);data-reactid
ordata-reactroot
attribute, see Warn when using React.unmountComponentAtNode on a different React instance's tree #3787 (comment));ReactDOMComponentTree.getInstanceFromNode
returnsnull
;[1] https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType