You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Android - Compose box - Draft message input reappears after clearing and navigating #98674
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:
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.
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.
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.
@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:
leaving within a second of clearing the input:
r98674-v2fast.mp4
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.
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.
Activity
applause-bot commentedon Aug 14, 2026
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
MelvinBot commentedon Aug 14, 2026
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 tofalse: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.tsxpassestrueas the 3rd arg), which is exactly the flag the edit composer is missing.Code references
true):ReportActionItemMessageEdit.tsx:158saveDraft:ReportActionItemMessageEdit.tsx:249(no delete path exists — clearing always writes'')'', no fallback to original):ReportActionItemMessageEdit.tsx:117-122shouldExecuteOnUnmount = false:useDebouncedSaveDraft.tstrue):ComposerWithSuggestions.tsx:295-302DRAFT_SAVE_DEBOUNCE_TIME):CONST/index.ts:2126ContextMenuActions.tsx:637What changes do you think we should make in order to solve the problem?
Pass
shouldExecuteOnUnmount = truewhen wiring the edit composer's debounced draft save atReportActionItemMessageEdit.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
shouldExecuteOnUnmountflag 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.
j3ffffff commentedon Aug 14, 2026
melvin-bot commentedon Aug 14, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @aimane-chnaif (
External)melvin-bot commentedon Aug 14, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022088353493538733792
skrohan5016-coder commentedon Aug 15, 2026
I don't think setting
shouldExecuteOnUnmount=trueon 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 thatReportActionItemMessageEditmust 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.useDebouncecancels 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, whileuseEditMessageshould cancel that pending write beforeclearAllReportActionDrafts()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.
melvin-bot commentedon Aug 17, 2026
@aimane-chnaif Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
melvin-bot commentedon Aug 19, 2026
@aimane-chnaif Eep! 4 days overdue now. Issues have feelings too...
melvin-bot commentedon Aug 21, 2026
@aimane-chnaif Still overdue 6 days?! Let's take care of this!
102 remaining items
yuvrajangadsingh commentedon Oct 26, 2026
@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:
r98674-v2fast.mp4
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.
sonofkratos92 commentedon Oct 27, 2026
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 updatesdraftstate and callsdebouncedSaveDraft(newDraft), which debouncessaveReportActionDraft(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 passingshouldExecuteOnUnmount = true. BecauseshouldExecuteOnUnmountdefaults tofalseinsrc/pages/inbox/report/useDebouncedSaveDraft.ts(lines 19, 32-42), unmountingReportActionItemMessageEditwithin 1000ms callsdebounced.cancel()instead ofdebounced.flush(), dropping the pendingsaveReportActionDraft(reportID, action, '')call. Even if the report screen stays mounted inReportsSplitNavigatorand only blurs (isFocusedbecomesfalse), neitherReportActionItemMessageEdit.tsxnoruseEditMessage.tsflushes the debounced draft on blur.Note that if we enable
shouldExecuteOnUnmount = truewithout cancelling on explicit draft deletion, pressing Save or Cancel callsdeleteDraft()->clearAllReportActionDrafts()(src/pages/inbox/report/ReportActionCompose/useEditMessage.tslines 56-64 andReportActionItemMessageEdit.tsxlines 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) andsrc/pages/inbox/report/useDebouncedSaveReportActionDraft.ts(line 35), we should exposeflushSaveDraft(debounced.flush) andcancelSaveDraft(debounced.cancel) and passshouldExecuteOnUnmount = truefor report action drafts.In
src/pages/inbox/report/ReportActionItemMessageEdit.tsx(lines 124-186) andsrc/pages/inbox/report/ReportActionCompose/useEditMessage.ts(lines 56-64), we should callcancelSaveDraft()insidedeleteDraft()(and in the deleted-action cleanup effect at lines 124-130) right beforeclearAllReportActionDrafts(), and add an effect that callsflushSaveDraft()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.samranahm commentedon Oct 27, 2026
@aimane-chnaif Were you able to reproduce this one?
aimane-chnaif commentedon Oct 27, 2026
@samranahm so you can still reproduce - "The draft message input is not empty. The previously cleared text reappears when returning to the report."?
samranahm commentedon Oct 27, 2026
@aimane-chnaif Looking closely at the video in OP this is what tester mean "text reappears when return..."
aimane-chnaif commentedon Oct 27, 2026
It's not bug. "The draft message input is not empty" - this should be bug but it seems no one is able to reproduce.
samranahm commentedon Oct 28, 2026
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.
samranahm commentedon Oct 30, 2026
Requested QA retest here https://expensify.slack.com/archives/C01GTK53T8Q/p1793319095430569
aimane-chnaif commentedon Oct 30, 2026
Closing https://expensify.slack.com/archives/C01GTK53T8Q/p1793388174873879?thread_ts=1793319095.430569&cid=C01GTK53T8Q