Fix missing bundle errors not correctly reported on Android (#52441)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Pieter De Baets
2025-07-08 05:58:56 -07:00
committed by Facebook GitHub Bot
parent db65cb70de
commit 6dfe59e1df
@@ -829,13 +829,6 @@ public class ReactHostImpl(
null
},
executor)
.continueWith({ task: Task<Void> ->
// TODO: validate whether errors during startup go through here?
if (task.isFaulted()) {
handleHostException(checkNotNull(task.getError()))
}
null
})
private fun getOrCreateReactContext(): BridgelessReactContext {
val method = "getOrCreateReactContext()"
@@ -952,9 +945,14 @@ public class ReactHostImpl(
},
bgExecutor)
val lifecycleUpdateTask = { task: Task<CreationResult> ->
val lifecycleUpdateTask = task@{ task: Task<CreationResult> ->
if (task.isFaulted()) {
// handleHostException may throw, so move it outside of the task scheduler
uiExecutor.execute { handleHostException(checkNotNull(task.getError())) }
return@task
}
val result = checkNotNull(task.getResult())
val reactInstance = result.instance
val reactContext = result.context
val isReloading = result.isReloading
val isManagerResumed = reactLifecycleStateManager.lifecycleState == LifecycleState.RESUMED
@@ -991,10 +989,9 @@ public class ReactHostImpl(
for (listener in reactInstanceEventListeners) {
listener.onReactContextInitialized(reactContext)
}
reactInstance
}
creationTask.onSuccess(lifecycleUpdateTask, uiExecutor)
creationTask.continueWith(lifecycleUpdateTask, uiExecutor)
creationTask.onSuccess({ task -> checkNotNull(task.getResult()).instance })
}
}