feat: make reactHost accessible#48338
Conversation
|
/rebase |
|
Thanks for sending this over @WoLewicki This sounds like a reasonable approach, but I'd like to have @mdvacca 's opinion on this as well |
|
IIRC for internal apps use-case we were able to make use of cc: @shwanton |
| /** Cleanup function for brownfield scenarios. */ | ||
| public abstract void invalidate(); |
There was a problem hiding this comment.
I see that ReactNativeHost already has a clear() method.
Could we instead do the invalidation in the DefaultReactHost.clear() method instead of having to create a brand new invalidate() abstract method?
There was a problem hiding this comment.
Ok so clear is a public API for cleaning all of those instances? If so, I think it will be the correct place to put it there then.
There was a problem hiding this comment.
I changed it but I am not sure if the INSTANCE is the proper way of getting the instance of kotlin object.
| public fun invalidate() { | ||
| reactHost = null | ||
| } |
There was a problem hiding this comment.
can you instead override fun clear(), call super.clear() and set the reactHost to null here?
There was a problem hiding this comment.
I am not sure I get it. DefaultReactHost does not inherit from ReactNativeHost so how can I override clear method in it? Or am I messing it up?
There was a problem hiding this comment.
@WoLewicki you're right, I misread the class title.
I'd suggest instead we do the following:
- Here make
public fun invalidate()beinternal - Inside DefaultReactNativeHost add the following:
override fun clear() {
super.clear()
DefaultReactHost.invalidate()
}| mReactInstanceManager.invalidate(); | ||
| mReactInstanceManager = null; | ||
| } | ||
| DefaultReactHost.INSTANCE.invalidate(); |
There was a problem hiding this comment.
this is probably not needed
|
@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@cortinico merged this pull request in 07769d4. |
|
This pull request was successfully merged by @WoLewicki in 07769d4 When will my fix make it into a release? | How to file a pick request? |
|
@WoLewicki sorry this took a bit longer. I've also update the commit message/description to reflect the correct behavior 07769d4 |
|
Ok thanks |
Summary:
On bridgeless mode,
reactHostis kept in memory even after destroying theDefaultReactNativeHostin brownfield scenario. Since it keeps references to the modules, they are not deallocated, and theirinitializemethods are not fired again when creating new instance ofreact-nativelater. It breaks the behavior of e.g.react-native-screens, which wants to listen for mutations and should get newFabricUIManager: https://github.com/software-mansion/react-native-screens/blob/20b7e83782cd5f79ddd0d61dadc13eeb4db4b258/android/src/main/java/com/swmansion/rnscreens/ScreensModule.kt#L45.By adding
invalidatemethod, which cleans up thereactHostinstance, we can achieve it.Changelog:
[ANDROID] [FIXED] - add
invalidatemethod for destroyingreactHostinstance.Test Plan:
In brownfield scenario, destroy the instance of RN and see that modules are also destroyed.