You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Unable to use unmountComponentAtNode with unstable_createRoot #21441
The case where it doesn't is if you render first, then unmountComponentAtNode, thencreateRoot on the same node, and then unmountComponentAtNode. This seems a bit like an unlikely combination to me. I don't think this is worth fixing but if this comes up again, we'll do that.
I think the situation you're talking about with the "render > unmount > render > unmount" is what I ran into.
I was rendering a React component in Node-RED Dashboard which, if you update a node, re-runs your entrypoint in the dashboard. I was making sure to unmount before remounting, but it was still mounting and unmounting multiple times in the same page load.
I later changed this whole system to render the React app into an iframe using the srcdoc attribute so there was only ever one mount on a given root node.
Activity
eps1lon commentedon May 6, 2021
unmountComponentAtNodeonly works with legacy roots i.e.ReactDOM.render.For the new roots you have the method directly on the root:
Does this work for you?
Edit:
Though for migration purposes an additional warning similar to https://github.com/facebook/react/blob/bd070eb2c489a1f758e4a55b193820af7346fa15/packages/react-dom/src/client/ReactDOMLegacy.js#L345-L354 would be nice.
Sawtaytoes commentedon May 6, 2021
Something like that would've saved me 2 hours tonight 😄. Definitely a reasonable solution.
I'd also say it should be on Reactjs.org:
This is the other place I checked:
https://reactjs.org/docs/concurrent-mode-adoption.html
eps1lon commentedon May 6, 2021
Documentation for
experimentalis not updated frequently and not viable considering the nature of these release channels.gaearon commentedon Jun 23, 2021
If you do
unmountComponentAtNode()on a node that was previously only passed tocreateRootthen it does warn already.https://codesandbox.io/s/awesome-euclid-sqhz1?file=/src/index.js
The case where it doesn't is if you
renderfirst, thenunmountComponentAtNode, thencreateRooton the same node, and thenunmountComponentAtNode. This seems a bit like an unlikely combination to me. I don't think this is worth fixing but if this comes up again, we'll do that.Sawtaytoes commentedon Jun 23, 2021
@gaearon It has an error message now :P.
I think the situation you're talking about with the "render > unmount > render > unmount" is what I ran into.
I was rendering a React component in Node-RED Dashboard which, if you update a node, re-runs your entrypoint in the dashboard. I was making sure to unmount before remounting, but it was still mounting and unmounting multiple times in the same page load.
I later changed this whole system to render the React app into an iframe using the
srcdocattribute so there was only ever one mount on a given root node.