Skip to content

[$125] Attachment - Unable to submit or share large pdf file via native app #67908

Closed

Description

@nlemma

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: V9.1.89-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail: https://test-management.browserstack.com/projects/2219752/folder/13176721/test-cases/41236970
Email or phone of affected tester (no customers): Slottwo1 7423@gmail.com
Issue reported by: Applause Internal Team
Device used: Redminote 10s android 13 phone
App Component: Chat Report View

Action Performed:

  1. Keep app logged in
  2. Open a large pdf - send - select expensify app
  3. Select a chat
  4. Try to submit/ share the file

Expected Result:

User must be able to submit or share file via native app.

Actual Result:

Unable to submit or share large pdf file and error is also not shown when action cannot be performed.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6908020_1754372462452.Screenrecorder-2025-08-05-11-04-32-529.mp4

Bug6908020_1754372836421!LARGE_PDF_FILE__1_.pdf

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021952841206235305205
  • Upwork Job ID: 1952841206235305205
  • Last Price Increase: 2025-08-05
  • Automatic offers:
    • rohit9625 | Contributor | 108372807
Issue OwnerCurrent Issue Owner: @suneox

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Aug 5, 2025
  2. melvin-bot commented on Aug 5, 2025

    @melvin-bot

    Triggered auto assignment to @OfstadC (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. rohit9625 commented on Aug 5, 2025

    @rohit9625
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Unable to submit or share any PDF file (either large or small), and the error is also not shown when the action cannot be performed. Also, the attachment preview is not shown at step 4.

    What is the root cause of that problem?

    When we try to submit or share any PDF file to the chat selected in step 3, the Share button doesn't work, and the Attachment Preview of the PDF file is empty, as can be seen in this screenshot:

    It happens because both AttachmentModal(used to show preview) and handleShare(called when tapping Share) function relies on validFilesToUpload state. In this case, the validFilesToUpload === 0 and handleShare returns because of this condition here:

    const handleShare = () => {
    if (!currentAttachment || validFilesToUpload.length === 0) {
    return;
    }

    And AttachmentModal doesn't show any preview because source(validFilesToUpload.at(0)) doesn't exists:
    <AttachmentModal
    headerTitle={fileName}
    source={validFilesToUpload.at(0)?.uri}
    originalFileName={fileName}

    Let's see why the validFilesToUpload was empty?
    Look at this code block:

    const [validFilesToUpload, setValidFilesToUpload] = useState<FileObject[]>([]);
    const {validateFiles} = useFilesValidation(setValidFilesToUpload);
    const report: OnyxEntry<ReportType> = getReportOrDraftReport(reportOrAccountID);
    const displayReport = useMemo(() => getReportDisplayOption(report, unknownUserDetails, reportAttributesDerived), [report, unknownUserDetails, reportAttributesDerived]);
    useEffect(() => {
    if (!currentAttachment || isTextShared || validFilesToUpload.length !== 0) {
    return;
    }
    validateFiles([{name: currentAttachment.id, uri: currentAttachment.content, type: currentAttachment.mimeType}]);
    }, [currentAttachment, isTextShared, validFilesToUpload.length, validateFiles]);

    • The validFilesToUpload state updates in the useFilesValidation hook as we pass setValidFilesToUpload to the hook
    • The hook returns validateFiles function which is called inside the above useEffect when the ShareDetailsPage mounted, after selecting a chat at step 3
    • We pass the currentAttachment to the validateFiles function, and it calls validateAndResizeFiles as the files.length is 1:
      validateAndResizeFiles(files, items ?? []);
    • The validateAndResizeFiles calls isValid for each file, which further calls normalizeFileObject and so on.
    • At last, here we get the PDF file after successful validation:
      .then(({processedFiles, pdfsToLoad}) => {
      if (pdfsToLoad.length) {
      validFiles.current = processedFiles;
      setPdfFilesToRender(pdfsToLoad);
      } else {
    • However, we do not call the proceedWithFilesAction function passed as setValidFilesToUpload from the ShareDetailsPage, like we do for the processedFiles here:
      } else if (processedFiles.length > 0) {
      const sortedFiles = sortFilesByOriginalOrder(processedFiles, originalFileOrder.current);
      proceedWithFilesAction(sortedFiles);
      resetValidationState();
      }

    Hence, the validFilesToUpload remains empty even though the file was validated, resulting in broken Attachment Preview and Share button not working.

    What changes do you think we should make in order to solve the problem?

    To solve the issue, we just need to call the proceedWithFilesAction here:

    .then(({processedFiles, pdfsToLoad}) => {
        if (pdfsToLoad.length) {
            validFiles.current = processedFiles;
            setPdfFilesToRender(pdfsToLoad);
            proceedWithFilesAction(pdfsToLoad); // set the validFilesToUpload

    However, seeing the complexity of the useFilesValidation hook, we should look for if we need the other checks as we are doing for processedFiles here:

    if (collectedErrors.current.length > 0) {
    const uniqueErrors = Array.from(new Set(collectedErrors.current.map((error) => JSON.stringify(error)))).map((errorStr) => JSON.parse(errorStr) as ErrorObject);
    setErrorQueue(uniqueErrors);
    setCurrentErrorIndex(0);
    const firstError = uniqueErrors.at(0);
    if (firstError) {
    setFileError(firstError.error);

    But, if we look at the flow of operation for the PDF file, then those checks seems redundant for pdfFilesToRender. Anyways, we can discuss this at the PR phase for sure :)

    Results: Now, the Share button works and Attachment Preview is shown.

    Screen_recording_20250806_005027.mp4

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    I don't think we have tests for Share flow.

    What alternative solutions did you explore? (Optional)

    As an alternative, we can make use of the PDFValidationComponent exported from the useFilesValidation hook, as it calls the checkIfAllValidatedAndProceed function when PDF loaded successfully:

    onLoadSuccess={() => {
    validatedPDFs.current.push(file);
    validFiles.current.push(file);
    checkIfAllValidatedAndProceed();
    }}

    Which further calls:
    const sortedFiles = sortFilesByOriginalOrder(validFiles.current, originalFileOrder.current);
    proceedWithFilesAction(sortedFiles);
    resetValidationState();

    We can make these changes at the ShareDetailsPage file:

    -     const {validateFiles} = useFilesValidation(setValidFilesToUpload);
    +    const {validateFiles, PDFValidationComponent} = useFilesValidation(setValidFilesToUpload);
    //  Other code
        </View>
        <SafeAreaView>
    +        {PDFValidationComponent}
              <AttachmentModal
                  headerTitle={fileName}
                  source={validFilesToUpload.at(0)?.uri}
                  originalFileName={fileName}
                  fallbackSource={FallbackAvatar}
              >

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Aug 5, 2025
  5. changed the title [-]Attachment - Unable to submit or share large pdf file via native app[/-] [+][$250] Attachment - Unable to submit or share large pdf file via native app[/+] on Aug 5, 2025
  6. melvin-bot commented on Aug 5, 2025

    @melvin-bot
  7. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Aug 5, 2025
  8. melvin-bot commented on Aug 5, 2025

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @suneox (External)

  9. melvin-bot commented on Aug 8, 2025

    @melvin-bot

    @suneox Whoops! This issue is 2 days overdue. Let's get this updated quick!

  10. suneox commented on Aug 9, 2025

    @suneox
    Contributor

    The alternative solution from @rohit9625 LGTM. We can apply the same approach that's already used in the existing IOU request flow.

    🎀 👀 🎀 C+ reviewed

  11. 20 remaining items

  12. melvin-bot commented on Aug 28, 2025

    @melvin-bot

    @suneox Eep! 4 days overdue now. Issues have feelings too...

  13. rohit9625 commented on Aug 30, 2025

    @rohit9625
    Contributor

    Hi @OfstadC, I think we should retest this issue and proceed with further steps :)

  14. melvin-bot commented on Sep 1, 2025

    @melvin-bot

    @suneox Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

  15. OfstadC commented on Sep 2, 2025

    @OfstadC
    Contributor

    I've confirmed we'd pay $125 here so working on payment now

  16. rohit9625 commented on Sep 2, 2025

    @rohit9625
    Contributor

    I've confirmed we'd pay $125 here so working on payment now

    Well, I just received an offer with amount $150. Do you want to edit that?

  17. OfstadC commented on Sep 2, 2025

    @OfstadC
    Contributor
  18. rohit9625 commented on Sep 2, 2025

    @rohit9625
    Contributor

    No problem, I accepted the new offer. Thank you :)

  19. changed the title [-][$250] Attachment - Unable to submit or share large pdf file via native app[/-] [+][$125] Attachment - Unable to submit or share large pdf file via native app[/+] on Sep 2, 2025
  20. melvin-bot commented on Sep 2, 2025

    @melvin-bot

    ⚠️ Failed to update price automatically. The BZ team member will need to update the price manually in Upwork.

  21. OfstadC commented on Sep 2, 2025

    @OfstadC
    Contributor

    Payment Summary

  22. garrettmknight commented on Sep 30, 2025

    @garrettmknight
    Contributor

    $125 approved for @suneox

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions