react-native-community/discussions-and-proposals

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

Kshitij09-sc opened this issue · 2 comments

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

  • Can we move this to background thread and think of other ways of thread confinement and safety?

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.

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?