Our application consists of lots of legacy code written using jQuery and some newer React components. We have mostly been able to handle separating concerns between the two, most of our code is one or the other - but occasionally we have React Components within JQuery Components.
In most cases: JQuery creates a Div, the Div Element is passed to a ReactDOM.render and control for that div is controlled by react. Then before JQuery destroys the Div it will call ReactDOM.unmountComponentAtNode to do the tear down.
However we have some JQuery code that is being removed in a way that is not trivial to detect that some of it is actually React, creating a component memory leak.
The correct fix for us it to solve the tear down, so that the unMounts are always called correctly, but there are engineering risks in this as the legacy code is not the cleanest and the risk of introduction of new bugs is high.
My question is whether there is a way that React Components can spot that they have become orphaned. ComponentWillUnmount is not the answer (as it does not get called in this scenario).