-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Can not prevent portal unmounting when using ReactDOM.createPortal #10826
Comments
Unmounting on parent unmount looks like a feature, not a bug to me. Perhaps doing something similar to what |
+1 |
Actually, we cannot, we are maintaining a common UI component rc-dialog. We cannot prohibit other developers unmount our dialog, this is why it is a problem to us(And we know that it may not be a problem to others). |
This is a problem for us too. |
Having the same issue, and the only solution i've found is to not use createPortal :( |
Hey y'all. I don't think the old behavior was actually supported, even if it sort of worked most of the time. The subtree component may have stayed rendered but it would be in an orphaned state, and likely to break if any update occurred on it, because the assumption was that the subtree is always actually parented. I've personally run into bugs where I've had the parent component unmount and then break something in the portal component on the next update cycle. |
The best work-around I can think of is to do a How would the api for this look like? Would this be too inflexible?
|
It seems like the use case was not really supported in the past either and led to errors. So I think we can’t say this is a “missing feature” of the portal API. It just isn’t as easily broken as the existing old API. If you have specific API suggestions around this problem please create an RFC: https://github.com/reactjs/rfcs Thanks! |
So, any solutions here? It's still a problem for me too... Cannot figure out how to prevent portal unmounts... |
You usually want to prevent a portal parent from unmounting in a case, when you have some kind of a dropdown component, which should open a modal on click inside. Because it's a dropdown, it hides on click inside, and that triggers a modal to unmount too. We've fixed this problem by rendering hidden content of a dropdown with a |
This was exactly my issue but I handle it like this, I added a preventAutoClose prop to my dropdown items as when I click on the item I had an auto close function that ran on this was my solution:
so I just add |
Previous comment #10143 (comment)
When we use
unstable_renderIntoContainer
implements portal, we can control when the portal unmount, this seems impossible when usecreatePortal
, because when parent component unmount, portal will be unmount by React itself.The text was updated successfully, but these errors were encountered: