Skip to content

Conversation

@CatLover01
Copy link

@CatLover01 CatLover01 commented Jan 2, 2026

After React context reload, the document picker's coroutine scope was canceled in onHostDestroy() but never recreated, causing subsequent launch {} calls to silently no-op and promises to never resolve.

Changes

Scope lifecycle management:

  • Changed fileCopyingCoroutine from val to var to allow recreation
  • Added createCoroutineScope(): constructs scope with SupervisorJob() + Dispatchers.IO
  • Added ensureScopeActive(reason): checks scope.isActive before launch, recreates if canceled
  • SupervisorJob prevents individual job failures from canceling entire scope

Updated coroutine launch sites:

  • processFilePickerResult() (critical path)
  • keepLocalCopy()
  • writeDocuments()

Fixes: #907 #910

@changeset-bot
Copy link

changeset-bot bot commented Jan 2, 2026

⚠️ No Changeset found

Latest commit: 0b96cd6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vonovak
Copy link
Member

vonovak commented Jan 2, 2026

hello and thanks for opening the PR!

After React context reload, the document picker's coroutine scope was canceled in onHostDestroy() but never recreated

that sounds odd to me, because the coroutine scope is created when the native module is created (=the first time it's called in JS). And after onHostDestroy (=app being killed), the module will be again recreated from scratch. If you determined that coroutine cancelation in onHostDestroy is the culprit, I suggest to remove that cancelation altogether from there. It's not much use anyway. Can you check if this fixes your issue? #912

thank you!

1 similar comment
@vonovak
Copy link
Member

vonovak commented Jan 2, 2026

hello and thanks for opening the PR!

After React context reload, the document picker's coroutine scope was canceled in onHostDestroy() but never recreated

that sounds odd to me, because the coroutine scope is created when the native module is created (=the first time it's called in JS). And after onHostDestroy (=app being killed), the module will be again recreated from scratch. If you determined that coroutine cancelation in onHostDestroy is the culprit, I suggest to remove that cancelation altogether from there. It's not much use anyway. Can you check if this fixes your issue? #912

thank you!

@CatLover01 CatLover01 closed this Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] keepLocalCopy hangs after app restart and never resolves

2 participants