Skip to content

Commit

Permalink
moveToResumedLifecycleState must be called from UI thread
Browse files Browse the repository at this point in the history
Summary:
I was seeing a SoftException in our apps due to this method being called as part of ReactInstanceManager's init. It seems inconsistent that we would call this from a background thread when all other `onHost*` methods are marked as confined to the UI thread.

Changelog: [Internal]

Reviewed By: ryancat

Differential Revision: D34340210

fbshipit-source-id: 0104eda66b2ca6bb315e64e806e9a30409d0d45c
  • Loading branch information
javache authored and facebook-github-bot committed Feb 18, 2022
1 parent bb7214b commit fc35a65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,6 @@ private void setupReactContext(final ReactApplicationContext reactContext) {

mDevSupportManager.onNewReactContextCreated(reactContext);
mMemoryPressureRouter.addMemoryPressureListener(catalystInstance);
moveReactContextToCurrentLifecycleState();

ReactMarker.logMarker(ATTACH_MEASURED_ROOT_VIEWS_START);
for (ReactRoot reactRoot : mAttachedReactRoots) {
Expand All @@ -1197,6 +1196,8 @@ private void setupReactContext(final ReactApplicationContext reactContext) {
new Runnable() {
@Override
public void run() {
moveReactContextToCurrentLifecycleState();

for (com.facebook.react.ReactInstanceEventListener listener : finalListeners) {
// Sometimes this listener is null - probably due to race
// condition between allocating listeners with a certain
Expand All @@ -1208,10 +1209,6 @@ public void run() {
}
}
});
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
// Mark end of bridge loading
ReactMarker.logMarker(ReactMarkerConstants.REACT_BRIDGE_LOADING_END);
reactContext.runOnJSQueueThread(
new Runnable() {
@Override
Expand All @@ -1227,6 +1224,11 @@ public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
}
});

Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
// Mark end of bridge loading
ReactMarker.logMarker(ReactMarkerConstants.REACT_BRIDGE_LOADING_END);
}

private void attachRootViewToInstance(final ReactRoot reactRoot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public void removeWindowFocusChangeListener(WindowFocusChangeListener listener)
}

/** Should be called by the hosting Fragment in {@link Fragment#onResume} */
@ThreadConfined(UI)
public void onHostResume(@Nullable Activity activity) {
mLifecycleState = LifecycleState.RESUMED;
mCurrentActivity = new WeakReference(activity);
Expand Down Expand Up @@ -282,6 +283,7 @@ public void onNewIntent(@Nullable Activity activity, Intent intent) {
}

/** Should be called by the hosting Fragment in {@link Fragment#onPause} */
@ThreadConfined(UI)
public void onHostPause() {
mLifecycleState = LifecycleState.BEFORE_RESUME;
ReactMarker.logMarker(ReactMarkerConstants.ON_HOST_PAUSE_START);
Expand Down

0 comments on commit fc35a65

Please sign in to comment.