Skip to content

Android - Compose box - Draft message input reappears after clearing and navigating #98674

Closed

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.4.53-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/69179363/folder/13177078/41237914/1659890711?sort=%2Bstatus_id
Email or phone of affected tester (no customers): casluyo@gmail.com
Issue reported by: Applause Internal Team
Bug source: Regression TC Execution
Device used: samsung s25/ android 16
App Component: Other

Action Performed:

  1. Open the Expensify app
  2. Open any report
  3. Send a message
  4. Press the Edit button in the newly added message
  5. Clear the draft message input (delete all text)
  6. Navigate to a different report
  7. Return to the first report

Expected Result:

The draft message input should remain empty after being cleared, even when navigating away and returning to the report.

Actual Result:

The draft message input is not empty. The previously cleared text reappears when returning to the report.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7233794_1786727345766.Screen_Recording_20260814_115947_Expensify.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Svetlana Lazutkina
Bug ID: 7233794

Upwork Automation - Do Not Edit

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Aug 14, 2026
  2. applause-bot commented on Aug 14, 2026

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/430d071f03145b182dec5aecd0c8720122491b465c67d9448259db3652339720

  3. MelvinBot commented on Aug 14, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    When you enter edit mode, the message's original text is immediately written to the report-action draft in Onyx (ContextMenuActions.tsx → saveReportActionDraft). While editing, every keystroke — including clearing to empty — is saved through a 1000ms-debounced save.

    The bug is a missing flush-on-unmount flag. The edit composer wires its debounced save without shouldExecuteOnUnmount, which defaults to false:

    const {saveDraft, ...} = useDebouncedSaveDraft(saveReportActionDraft); // no 3rd arg → shouldExecuteOnUnmount = false
    

    So if you clear the text and navigate away within 1000ms, the pending {message: ''} write is cancelled on unmount rather than flushed. Onyx still holds the original message from when edit mode was entered, and on return the composer re-reads that original text — so the cleared text reappears.

    This is not Android-specific — the logic is shared cross-platform. It's a timing race, which is why quick navigation (as in regression testing) reliably reproduces it.

    The sibling report-comment composer already opts into the flush (ComposerWithSuggestions.tsx passes true as the 3rd arg), which is exactly the flag the edit composer is missing.

    Code references

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

    Pass shouldExecuteOnUnmount = true when wiring the edit composer's debounced draft save at ReportActionItemMessageEdit.tsx:158, mirroring the report-comment composer. This flushes the pending draft write (including the empty one) on unmount instead of cancelling it, so the cleared state persists across navigation.

    What alternative solutions did you explore? (Optional)

    An alternative would be to flush the debounced save synchronously in the edit composer's own unmount/cleanup effect, but reusing the existing shouldExecuteOnUnmount flag is simpler and consistent with the comment composer.

    A note on scope / product intent

    Submitting an empty edit already triggers a delete-message confirmation on save. This fix is only about persisting the in-progress cleared draft across navigation and does not change that submit behavior.

    Verification note

    Root cause was traced directly from the code (deterministic — no runtime confirmation needed). A web repro via the automated tester wasn't possible because the tooling can't trigger the hover/right-click Edit affordance; this is a tooling limitation, not a contradiction of the analysis.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/98674) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Aug 14, 2026
  5. j3ffffff commented on Aug 14, 2026

    @j3ffffff
  6. melvin-bot commented on Aug 14, 2026

    @melvin-bot

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

  7. melvin-bot commented on Aug 14, 2026

    @melvin-bot
  8. skrohan5016-coder commented on Aug 15, 2026

    @skrohan5016-coder

    I don't think setting shouldExecuteOnUnmount=true on the edit composer is safe by itself. That exact path was deliberately left opt-out in #95471 after review caught the opposite regression: if the user presses Save or Cancel before the one-second timer fires, deleteDraft() clears the action drafts and unmounts the editor, then an unmount flush writes the stale edit back. The final review explicitly verified that ReportActionItemMessageEdit must keep cancel-on-unmount for that reason: #95471 (comment)

    The new repro is the other exit path. Clearing the editor calls the debounced saveDraft(..., ''), but navigating to another report unmounts it before the timer fires. useDebounce cancels that pending call by default, so Onyx retains the older action draft and restores it when the report is reopened. One unmount boolean cannot distinguish “leave this report with an in-progress edit” from “finish or discard this edit”.

    I would expose explicit flush and cancel controls from useDebouncedSaveDraft. The navigation/unmount path should flush the latest pending edit, while useEditMessage should cancel that pending write before clearAllReportActionDrafts() runs for Save, Cancel, or confirmed delete. This preserves drafts across report navigation without reintroducing the stale-draft-after-save regression that #95471 fixed.

    The regression test needs both transitions under fake timers: navigate before one second and reopen with the latest draft, including an empty draft; then Save or Cancel before one second and verify the action draft stays cleared. Special-casing only the empty string would still lose a non-empty edit made immediately before navigation.

  9. melvin-bot commented on Aug 17, 2026

    @melvin-bot

    @aimane-chnaif Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  10. melvin-bot commented on Aug 19, 2026

    @melvin-bot

    @aimane-chnaif Eep! 4 days overdue now. Issues have feelings too...

  11. melvin-bot commented on Aug 21, 2026

    @melvin-bot

    @aimane-chnaif Still overdue 6 days?! Let's take care of this!

  12. 102 remaining items

  13. yuvrajangadsingh commented on Oct 26, 2026

    @yuvrajangadsingh
    Contributor

    @aimane-chnaif my proposal doesn't change any product code, so there's no after-fix video. both of these are on current main (c7cae02), android 15 emulator, dev build, following the OP steps:

    1. leaving within a second of clearing the input:
    r98674-v2fast.mp4
    1. leaving a few seconds after clearing it:
    r98674-v2slow.mp4

    in both, the input is empty when i come back to the report. the edit is closed and the message keeps its sent text, which matches the expected result in the OP.

  14. sonofkratos92 commented on Oct 27, 2026

    @sonofkratos92

    Proposal

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

    On Android, when you edit a message, clear the text in the edit input, and switch to another report from the header before saving, going back to the first report shows the old draft text again.

    What is the root cause of that problem?

    In src/pages/inbox/report/ReportActionItemMessageEdit.tsx (lines 149-175), editing or clearing the text updates draft state and calls debouncedSaveDraft(newDraft), which debounces saveReportActionDraft(reportID, action, newDraft) by 1000ms (CONST.TIMING.DRAFT_SAVE_DEBOUNCE_TIME).

    In src/pages/inbox/report/useDebouncedSaveReportActionDraft.ts (line 35), useDebouncedSaveDraft(saveDraftWithLatestOfflineState) is called without passing shouldExecuteOnUnmount = true. Because shouldExecuteOnUnmount defaults to false in src/pages/inbox/report/useDebouncedSaveDraft.ts (lines 19, 32-42), unmounting ReportActionItemMessageEdit within 1000ms calls debounced.cancel() instead of debounced.flush(), dropping the pending saveReportActionDraft(reportID, action, '') call. Even if the report screen stays mounted in ReportsSplitNavigator and only blurs (isFocused becomes false), neither ReportActionItemMessageEdit.tsx nor useEditMessage.ts flushes the debounced draft on blur.

    Note that if we enable shouldExecuteOnUnmount = true without cancelling on explicit draft deletion, pressing Save or Cancel calls deleteDraft() -> clearAllReportActionDrafts() (src/pages/inbox/report/ReportActionCompose/useEditMessage.ts lines 56-64 and ReportActionItemMessageEdit.tsx lines 178-186) and unmounts the editor, which would flush the old draft back into Onyx on unmount.

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

    In src/pages/inbox/report/useDebouncedSaveDraft.ts (lines 19-45) and src/pages/inbox/report/useDebouncedSaveReportActionDraft.ts (line 35), we should expose flushSaveDraft (debounced.flush) and cancelSaveDraft (debounced.cancel) and pass shouldExecuteOnUnmount = true for report action drafts.

    In src/pages/inbox/report/ReportActionItemMessageEdit.tsx (lines 124-186) and src/pages/inbox/report/ReportActionCompose/useEditMessage.ts (lines 56-64), we should call cancelSaveDraft() inside deleteDraft() (and in the deleted-action cleanup effect at lines 124-130) right before clearAllReportActionDrafts(), and add an effect that calls flushSaveDraft() when the screen loses focus (!isFocused) so switching reports immediately saves the cleared draft.

    What alternative solutions did you explore? (Optional)

    Saving immediately only when newDraft.trim() === '' would fix full clears, but if a user partially edits a draft and switches reports within 1s, that edit would still be lost unless we flush on blur and unmount.

  15. samranahm commented on Oct 27, 2026

    @samranahm
    Contributor

    @aimane-chnaif Were you able to reproduce this one?

  16. aimane-chnaif commented on Oct 27, 2026

    @aimane-chnaif
    Contributor

    I can still reliably reproduce this.

    @samranahm so you can still reproduce - "The draft message input is not empty. The previously cleared text reappears when returning to the report."?

  17. samranahm commented on Oct 27, 2026

    @samranahm
    Contributor

    @aimane-chnaif Looking closely at the video in OP this is what tester mean "text reappears when return..."

    Image
  18. aimane-chnaif commented on Oct 27, 2026

    @aimane-chnaif
    Contributor

    It's not bug. "The draft message input is not empty" - this should be bug but it seems no one is able to reproduce.

  19. samranahm commented on Oct 28, 2026

    @samranahm
    Contributor

    Yep! I got it. Thanks for explaining Aimane.

    @Expensify/applause Could you take a look at this if you can produce this, or let's close this one since no one is able to reproduce.

  20. samranahm commented on Oct 30, 2026

    @samranahm
    Contributor
  21. aimane-chnaif commented on Oct 30, 2026

    @aimane-chnaif
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions