From 70df3ea10a28461845ebf8970fbb3d5dcf057e8f Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 30 Nov 2025 14:06:19 +0000 Subject: [PATCH 1/2] fix: use promiseWrapper for all rejections in pick, pickDirectory, and saveDocument The pick, pickDirectory, and saveDocument functions were using both promiseWrapper.trySetPromiseRejectingIncoming() to set the promise and direct promise.reject() calls in catch blocks. This led to an inconsistent state where the promiseWrapper would still hold a reference to the rejected promise, causing subsequent calls to automatically reject. Changed all promise.reject() calls in catch blocks to use promiseWrapper.reject() to ensure proper cleanup of the wrapper state. --- .../RNDocumentPickerModule.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/document-picker/android/src/main/java/com/reactnativedocumentpicker/RNDocumentPickerModule.kt b/packages/document-picker/android/src/main/java/com/reactnativedocumentpicker/RNDocumentPickerModule.kt index 23201997..82ebb15d 100644 --- a/packages/document-picker/android/src/main/java/com/reactnativedocumentpicker/RNDocumentPickerModule.kt +++ b/packages/document-picker/android/src/main/java/com/reactnativedocumentpicker/RNDocumentPickerModule.kt @@ -96,9 +96,9 @@ class RNDocumentPickerModule(reactContext: ReactApplicationContext) : val intent = IntentFactory.getPickIntent(options) currentActivity.startActivityForResult(intent, PICK_FILES_REQUEST_CODE) } catch (e: ActivityNotFoundException) { - promise.reject(UNABLE_TO_OPEN_FILE_TYPE, e) + promiseWrapper.reject(UNABLE_TO_OPEN_FILE_TYPE, e) } catch (e: Exception) { - promise.reject(E_OTHER_PRESENTING_ERROR, e) + promiseWrapper.reject(E_OTHER_PRESENTING_ERROR, e) } } @@ -134,9 +134,9 @@ class RNDocumentPickerModule(reactContext: ReactApplicationContext) : } currentActivity.startActivityForResult(intent, SAVE_DOC_REQUEST_CODE) } catch (e: ActivityNotFoundException) { - promise.reject(UNABLE_TO_OPEN_FILE_TYPE, e) + promiseWrapper.reject(UNABLE_TO_OPEN_FILE_TYPE, e) } catch (e: Exception) { - promise.reject(E_OTHER_PRESENTING_ERROR, e) + promiseWrapper.reject(E_OTHER_PRESENTING_ERROR, e) } } @@ -163,9 +163,9 @@ class RNDocumentPickerModule(reactContext: ReactApplicationContext) : // TODO option for extra task on stack? currentActivity.startActivityForResult(intent, PICK_DIR_REQUEST_CODE) } catch (e: ActivityNotFoundException) { - promise.reject(UNABLE_TO_OPEN_FILE_TYPE, e) + promiseWrapper.reject(UNABLE_TO_OPEN_FILE_TYPE, e) } catch (e: Exception) { - promise.reject(E_OTHER_PRESENTING_ERROR, e) + promiseWrapper.reject(E_OTHER_PRESENTING_ERROR, e) } } From be41a8719a9ad1f89c634771a1545c58e0c2c3bf Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Sun, 30 Nov 2025 15:15:01 +0100 Subject: [PATCH 2/2] Fix promise rejections in document picker methods Updated promise handling in pick, pickDirectory, and saveDocument functions. --- .changeset/perfect-ways-try.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/perfect-ways-try.md diff --git a/.changeset/perfect-ways-try.md b/.changeset/perfect-ways-try.md new file mode 100644 index 00000000..b9554d41 --- /dev/null +++ b/.changeset/perfect-ways-try.md @@ -0,0 +1,5 @@ +--- +"@react-native-documents/picker": patch +--- + +fix: use promiseWrapper for all rejections in pick, pickDirectory, and saveDocument