Skip to content

Migrate ShareActionHandler to a type-safe Nitro module - #104435

Closed
roryabraham wants to merge 1 commit into
mainfrom
rory/nitro-share-action-handler
Closed

roryabraham wants to merge 1 commit into
mainfrom
rory/nitro-share-action-handler

Conversation

@roryabraham

@roryabraham roryabraham commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Replace the handwritten NativeModules.ShareActionHandler contract with a Nitrogen-generated ShareActionHandler in the existing @expensify/nitro-utils module. Swift and Kotlin now construct the same generated SharedFile record and return Promise<SharedFile[]>, rather than Android returning a JSON string and iOS returning dictionaries through a callback.

  • Preserve processedAt as a string of epoch milliseconds to match the existing Onyx model; make aspectRatio explicitly optional.
  • Keep SharedPreferences JSON and iOS app-group storage internal to native code. Validate persisted Android field types, reject missing/unreadable/empty attachments, return an empty array when no share is pending, and route rejected processing to the existing attachment-error UI.
  • Run native file processing off the JS thread. Preserve existing first-file selection and receipt/Share behavior.
  • Mark literal Android text explicitly so text starting with / is not mistaken for a file path and a missing text file is not shared as literal text. Retain compatibility with the older intent writers.
  • Configure the standalone iOS app-group identifier through Info.plist; retain the production hybrid group as the default for older hosts.
  • Remove standalone legacy bridge registrations/sources and the ambient TS declaration. The companion Mobile-Expensify PR removes its duplicate bridges and explicitly configures the hybrid app group.

This branches from main independently of #101208: it does not include that PR's cold-start persistence/routing changes. Reconcile the overlapping ShareRootPage and intent-handler changes before merging both.

MOBILE-EXPENSIFY: https://github.com/Expensify/Mobile-Expensify/pull/14192

Merge the App implementation before removing the legacy hybrid bridges in the companion PR.

Manual test plan — not yet run

  1. Check out this App branch and the linked Mobile-Expensify companion branch in the normal App/submodule layout, install dependencies, run npm run specs in modules/ExpensifyNitroUtils, and reinstall iOS pods/sync Gradle.
  2. Build fresh Android and iOS native binaries from Mobile-Expensify for hybrid testing; also build the supported standalone native variants. Do not test with an older binary or a JS-only update.
  3. Sign in, leave the app running, and share a JPEG/PNG receipt from Gallery/Photos into Expensify.
  4. Verify the receipt preview loads, its aspect ratio is correct, the Submit tab is selected for a scannable receipt, and submitting/sharing the attachment still works.
  5. Return to the source app and share a different receipt. Verify the new attachment replaces the previous one and reopening/resuming the Share screen does not crash.
  6. Share a supported PDF and video. Verify the existing Share flow, file-size validation, and preview behavior are retained.
  7. Share plain text and a URL. On Android also share literal text beginning with /. Verify the exact text is available in the Share flow, not interpreted as a missing attachment path.
  8. Share an actual .txt file and verify it remains an attachment rather than being interpreted as literal text.
  9. In a debug build, clear pending share storage and open new-expensify://share/root. Verify the existing attachment-error alert appears rather than leaving the screen on its skeleton.
  10. Using the simulator's app-group container or Android Device Explorer, make a pending attachment empty or remove its file before processing. On Android include a text/plain file share with isText: false. Verify processing reports an attachment error and never shares the missing path as literal text.
  11. In Android debug share storage, supply malformed JSON or non-string content/mimeType. Verify processing rejects and the Share screen displays an attachment error rather than crashing JS.
  12. Share an unsupported file type. Verify the existing wrong-file-type error appears.
  13. Force quit and share again on Android and iOS. Verify payload processing still works when the Share route opens; compare routing behavior with main, treating the known Android cold-start routing issue in Fix cold-start file sharing to open Submit expense #101208 separately rather than expecting this migration to fix it.
  14. Repeat the successful warm-start cases on both platforms in standalone and hybrid builds, and check for JS/native errors or missing Nitro module registrations.

AI Tests

  • Passed: Nitrogen 0.37.1 generation, TypeScript project checks, changed-file lint, React Compiler compliance, changed-file spelling, formatting checks, Storybook smoke test, and focused bridge/Share screen/Submit regression tests (14 tests).
  • Passed: Swift syntax parsing and plist/Xcode project syntax validation. These are not full native builds.
  • Full repository lint aborted with signal 6 / out-of-memory; no full-lint pass is claimed.
  • Full npm test -- --silent --maxWorkers=2 was attempted and stopped at the five-minute limit before completion. It reported failures in tests/unit/pages/HomePage.test.tsx because useIsFocused() could not find a navigation object. These are outside the changed Share code; they have not been baseline-verified or investigated here. No full-suite pass is claimed.
  • Android Kotlin compilation was attempted, but Gradle stopped during configuration because linked worktree dependencies resolved the Expo Gradle plugin through two included-build paths. Native compilation, device testing, and native storage/error-path integration coverage remain required before marking ready.
  • Nitrogen output is committed as generated; its whitespace-only lines are left untouched. git diff --check passes with generated end-of-line whitespace ignored.

Fixed Issues

$ #104432
PROPOSAL: N/A — internal architectural follow-up to #101208.

Tests

// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review".
// The numbered manual test plan above is proposed coverage, not a claim that device tests were performed.

  • Verify that no errors appear in the JS console

Offline tests

Proposed; not run:

  1. Sign in and enable airplane mode on Android and iOS.
  2. Share a receipt into an already-running app and verify the local attachment preview and Share/Submit tabs load without a network request being required for native processing.
  3. Share plain text and a supported PDF while offline and verify the local handoff still works.
  4. Repeat the missing/empty-attachment scenario and verify the attachment-error alert appears without a network connection.
  5. Restore connectivity and verify the selected attachment can still be submitted/shared normally.

QA Steps

// TODO: The human co-author must fill out the QA tests you ran before marking this PR as "ready for review".
// Use the numbered manual and offline test plans above as the proposed QA coverage.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

Generate one shared-file contract for Swift, Kotlin, and TypeScript. Keep native storage internal and preserve the existing Onyx timestamp format.

Refs: #104432
@roryabraham
roryabraham requested a review from a team October 20, 2026 03:42
@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/ShareActionHandlerModule/index.ts 0.00% <0.00%> (ø)
src/pages/Share/ShareRootPage.tsx 89.83% <85.71%> (+89.83%) ⬆️
... and 13 files with indirect coverage changes

@roryabraham

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T03:56:06.300684Z 8fda094 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 8fda09452b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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.

1 participant