Skip to content

Commit 6dfe59e

Browse files
javachefacebook-github-bot
authored andcommitted
Fix missing bundle errors not correctly reported on Android (#52441)
Summary: Pull Request resolved: #52441 When an error is thrown using `handleHostException` from within the (immediate) execution of a `Task`, the `Task` will capture the error. If those errors are never consumed, the error is just silently swallowed. Instead we should make sure that this is raised outside of the context of a `Task` so the error correctly bubbles up and crashes the app (in release). Changelog: [Internal] Reviewed By: rshest Differential Revision: D77798248 fbshipit-source-id: 41803aba0cace0e364a235501cf34bb946e7ff51
1 parent db65cb7 commit 6dfe59e

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -829,13 +829,6 @@ public class ReactHostImpl(
829829
null
830830
},
831831
executor)
832-
.continueWith({ task: Task<Void> ->
833-
// TODO: validate whether errors during startup go through here?
834-
if (task.isFaulted()) {
835-
handleHostException(checkNotNull(task.getError()))
836-
}
837-
null
838-
})
839832

840833
private fun getOrCreateReactContext(): BridgelessReactContext {
841834
val method = "getOrCreateReactContext()"
@@ -952,9 +945,14 @@ public class ReactHostImpl(
952945
},
953946
bgExecutor)
954947

955-
val lifecycleUpdateTask = { task: Task<CreationResult> ->
948+
val lifecycleUpdateTask = task@{ task: Task<CreationResult> ->
949+
if (task.isFaulted()) {
950+
// handleHostException may throw, so move it outside of the task scheduler
951+
uiExecutor.execute { handleHostException(checkNotNull(task.getError())) }
952+
return@task
953+
}
954+
956955
val result = checkNotNull(task.getResult())
957-
val reactInstance = result.instance
958956
val reactContext = result.context
959957
val isReloading = result.isReloading
960958
val isManagerResumed = reactLifecycleStateManager.lifecycleState == LifecycleState.RESUMED
@@ -991,10 +989,9 @@ public class ReactHostImpl(
991989
for (listener in reactInstanceEventListeners) {
992990
listener.onReactContextInitialized(reactContext)
993991
}
994-
reactInstance
995992
}
996993

997-
creationTask.onSuccess(lifecycleUpdateTask, uiExecutor)
994+
creationTask.continueWith(lifecycleUpdateTask, uiExecutor)
998995
creationTask.onSuccess({ task -> checkNotNull(task.getResult()).instance })
999996
}
1000997
}

0 commit comments

Comments
 (0)