Skip to content

Defer activity results through ReactHost tasks - #57051

Open
sorinc03 wants to merge 1 commit into
react:mainfrom
sorinc03:fix/android-activity-result-before-react-ready
Open

sorinc03 wants to merge 1 commit into
react:mainfrom
sorinc03:fix/android-activity-result-before-react-ready

Conversation

@sorinc03

@sorinc03 sorinc03 commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #52114.

Activity results can arrive while bridgeless React startup is already scheduled but the React context is not ready. Defer their delivery through the existing ReactInstance task rather than maintaining a separate queue.

callWithExistingReactContext reads the instance task on the host executor after previously requested startup work, then delivers on the UI executor once initialization succeeds. It does not start an otherwise unused host and drops delivery for a destroyed activity or a replaced instance.

This revision follows the requested Task-based approach and is rebased onto upstream 9c7b0f5.

Changelog

[ANDROID] [FIXED] - Deliver activity results received during bridgeless React context startup

Test Plan

JAVA_HOME=/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home \
ANDROID_HOME=/Users/sorincioban/Library/Android/sdk \
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest \
  --tests com.facebook.react.runtime.ReactHostTest \
  -Preact.internal.useHermesNightly=false --console=plain

13 tests passed, 0 failures/errors. Covers ready-context delivery, startup already scheduled, ordering/null intents, and destroyed activities. Changed Kotlin files pass ktfmt 0.59.0; git diff --check origin/main..HEAD passes.

Full native/device verification is left to CI and maintainer testing; it was not run locally.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 2, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jun 2, 2026
@sorinc03
sorinc03 force-pushed the fix/android-activity-result-before-react-ready branch from 18585d2 to e4fdb53 Compare June 4, 2026 08:16

@javache javache left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not super consistent about this, and this is probably an issue across multiple methods (eg onNewIntent) - we should build on the existing Task abstraction within ReactHost to schedule these instead, instead of having ad-hoc queues.

Maybe similarly to callWithExistingReactInstance, you could add a callWithExistingReactContext which queues up a task and waits for a react context?

@sorinc03

sorinc03 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Published the Task-based revision as 0405099, rebased onto upstream main 9c7b0f5. The fork's ownership-transfer lock is cleared and fork main is synced; the previous publishing blocker is resolved.

callWithExistingReactContext uses the existing ReactInstance task instead of an ad-hoc activity-result queue. It waits for already scheduled startup, delivers on the UI executor, and avoids delivery to a destroyed activity or replaced instance without starting an unused host.

Re-ran ReactHostTest on the published revision: 13 passed, 0 failures/errors. Changed Kotlin formatting and git diff --check pass. Full native/device verification remains pending CI. Updated the PR description and marked it ready for re-review.

@sorinc03
sorinc03 force-pushed the fix/android-activity-result-before-react-ready branch from e4fdb53 to 0405099 Compare October 29, 2026 15:09
@sorinc03 sorinc03 changed the title Queue activity results before React context is ready Defer activity results through ReactHost tasks Oct 29, 2026
@sorinc03
sorinc03 marked this pull request as ready for review October 29, 2026 15:10
@sorinc03

Copy link
Copy Markdown
Contributor Author

@javache The Task-based revision is now published in 0405099 and ready for re-review. It uses the existing ReactInstance task rather than a separate queue; all 13 focused ReactHost tests pass on the rebased commit. The earlier fork lock is resolved. CI is running; details and remaining native/device verification limits are in the updated description.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android ReactActivity Destroy Prevents Successful OnActivityResult Calls

2 participants