react-native-community / discussions-and-proposals

Discussions and proposals related to the main React Native project
https://reactnative.dev
1.69k stars 127 forks source link

[Question] Why ReactInstanceManager needs to be initialized on main thread? #786

Open Kshitij09-sc opened 5 months ago

Kshitij09-sc commented 5 months ago

Introduction

I noticed ReactInstanceManager methods have @ThreadConfined(UI) and has assertions around same. Wanted to understand why do we need to initialize this on main thread?

Details

https://github.com/facebook/react-native/blob/d94c4c46f27139d68d5303d0dafe106c4c685ea6/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java#L1117

Discussion points

cortinico commented 5 months ago

Can you elaborate more?

Specifically in your title you ask:

Why SoLoader needs to be initialized on main thread?

while in the issue body you point to runCreateReactContextOnNewThread. I'm unsure what you'r exactly asking.

Kshitij09-sc commented 5 months ago

Let's focus this question on ReactInstanceManager. I noticed SoLoader & these classes are somehow linked when it comes to initialization, but to keep it specific, why ReactInstanceManager needs to be initialized on main thread?