Skip to content

fix Expense - Unable to move undeleted expense to workspace - #102317

Merged
carlosmiceli merged 2 commits into
Expensify:mainfrom
samarroy84:fix-97677
Sep 25, 2026
Merged

carlosmiceli merged 2 commits into
Expensify:mainfrom
samarroy84:fix-97677

Conversation

@samarroy84

@samarroy84 samarroy84 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

After delete → undelete, the self-DM has two IOU actions for the same transaction (the old blanked one plus the new live one). When the expense is moved, the lookup can pick the blanked one. The new action copies its blanked message, so the moved expense shows as deleted and the report loads forever. The live thread is never moved to the new report, so opening the expense shows "not here".

Fix: a new opt-in shouldPreferLiveAction flag on getIOUActionForReportID/getIOUActionForTransactionID returns the live action when both exist. In every other case it returns the same action as before. Only getChangeTransactionsReportOnyxData and useChangeTransactionsReportReports pass it. Added a regression test.

Fixed Issues

$ #97677
PROPOSAL: #97677 (comment)

Tests

Prerequisite: Account has a Self DM and a workspace.

  1. Create a manual expense in the Self DM.
  2. Go to Spend > Expenses, select the expense and delete it.
  3. Go to Filters > Status > Deleted, select the expense and choose Undelete from the dropdown.
  4. Go back to the Self DM and open the expense.
  5. Tap the Report field > Create report.
  6. Verify the expense opens normally in the RHP ("Hmm… it's not here" isn't shown).
  7. Go to the workspace chat and open the report.
  8. Verify the report shows the expense, not an endless loading skeleton.
  • Verify that no errors appear in the JS console

Offline tests

Same as Tests

QA Steps

Same as Tests

  • 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 followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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 followed the guidelines as stated in the Review Guidelines
  • 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 any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • 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.
  • 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
test.mov

@samarroy84
samarroy84 marked this pull request as ready for review September 25, 2026 15:44
@samarroy84
samarroy84 requested review from a team as code owners September 25, 2026 15:44
@melvin-bot
melvin-bot Bot requested review from JmillsExpensify and situchan and removed request for a team September 25, 2026 15:44
@melvin-bot

melvin-bot Bot commented Sep 25, 2026

Copy link
Copy Markdown

@situchan Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

Comment thread src/libs/ReportActionsUtils.ts Resolved
@MelvinBot

Copy link
Copy Markdown
Contributor

Code review

Verdict: Looks good. I found no blocking issues. The fix targets the cause in the move flow. The hook and the action now pick the same live IOU action, so the live transaction thread gets re-parented. The regression test covers both parts. All CI checks pass except Check independent approval, which is expected before a reviewer approves.

Non-blocking points to consider:

  1. Other callers can still pick the blanked action. After an undelete, other flows use the default first match. Examples are useNavigateToTransactionThread.ts:59, hold/unhold in Hold.ts, and TransactionThreadNavigationUtils.ts:54. These could open the deleted thread for an undeleted self-DM expense. Keeping the flag opt-in is a safe choice for this PR. Still, please say in the PR whether you checked these flows, or file a follow-up.
  2. The root cause is probably in the backend. Undelete leaves the old blanked action with its IOUTransactionID still set. The move flow itself clears it (IOUTransactionID: null) when it retires an action. Clearing it on undelete would remove the duplicate at the source. That change is outside App, so this frontend guard is a reasonable defense until then.
  3. isLive depends on how isDeletedAction treats a missing message. In ReportActionsUtils.ts:2803, isDeletedAction treats a missing message as [], which counts as deleted. The !reportAction.message guard is correct and the comment explains it. A small unit test for getIOUActionForTransactionID alone would lock this in. Cover a single blanked match, blanked plus live in either order, and a pendingAction: delete match.
  4. Nit: The open AI review comment about the semicolon in the JSDoc (CONSISTENCY-15) is still unresolved.

I did not run the test steps in the app. This review covers the code only.


view run

@situchan

situchan commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
ios.mp4
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov

@melvin-bot
melvin-bot Bot requested a review from carlosmiceli September 25, 2026 16:04
@MelvinBot

MelvinBot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Web test steps verification results: ✅ pass

I found no regressions. Moving expenses between the Self DM and workspace reports worked in every case I tried: create report, remove from report, create report again, and delete then undelete. I also traced every caller of the move flow. The new flag changes the result only when the source report holds both a blanked action and a live action for the same expense, which is the bug case. The tool could not capture console logs, so step 8 relies on the absence of visible errors.
Undeleted expense opened in new report

Step Status
1. A never-deleted Self DM expense moved with Report > Create report opens normally in the RHPCreated a $25.00 "Melvin Test Merchant" expense in the Self DM, then used Report > Create report. The RHP showed "Expense Report 2026-09-25" with all expense fields and no "Hmm… it's not here" error.
Expense opened normally in new workspace report
✅
2. The new workspace report shows the expense with no endless loading skeletonThe new report showed the Merchant, Date, Category, Reimbursable, and Report fields right away, with no skeleton placeholders.
Workspace report showing the expense
✅
3. Moving the expense back to the Self DM (Remove from report) works and the expense opens normallyThe workspace report showed "No expenses yet". The Self DM showed "tracking $25.00", and the expense opened with a "moved this expense to your personal space" line.
Expense back in Self DM
✅
4. Moving the same expense to a workspace report again worksReport > Create report made a new report. The RHP opened with all expense fields and no skeleton or error.
Expense moved again to a new report
✅
5. A second expense is deleted in Spend > Expenses, then undeleted from the Deleted filterCreated a $40.00 "Melvin Delete Test" expense and deleted it. After Undelete, the Deleted filter showed "Nothing to show", which confirms the expense was restored.
Deleted status filter in Spend > Expenses
✅
6. The undeleted expense moved with Report > Create report opens normally in the RHPThe undeleted expense opened normally in the Self DM. Report > Create report opened it in a new report with no "Hmm… it's not here" error.
Undeleted expense opened in new report
✅
7. The workspace report from step 6 shows the expense with no endless loading skeletonThe report showed "Melvin Delete Test" with the Date, Category, Reimbursable, and Report fields right away and no skeleton loaders.
Undeleted expense opened in new report
✅
8. No JS console errors about report actions or transactionsThe web test tool cannot read console logs, so console errors were not captured. No error banners, "not here" screens, or stuck skeletons appeared during any step.
✅

view run · view recording

@JmillsExpensify JmillsExpensify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@carlosmiceli
carlosmiceli merged commit 10ee52a into Expensify:main Sep 25, 2026
37 of 40 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 carlosmiceli has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/carlosmiceli in version: 9.4.95-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site changes are needed for this PR, so I did not create a docs PR.

This PR fixes a bug in the code that picks which expense entry to move. The bug happened when you moved an undeleted expense to a report. It does not change any feature, setting, button, label, or step that a user sees. The expense now works the way the help site already says it should.

Why no docs update
  • Changed files: ReportActionsUtils.ts, Transaction.ts, useChangeTransactionsReportReports.ts, and a test. All of them are internal logic. There is no copy change and no change to src/languages.
  • Existing coverage: How-to-Delete-Expenses.md:77-86 already explains how to undelete an expense (Spend > Expenses > Status = Deleted > Selected > Undelete). It says restored expenses return to your account. It does not describe the bug, so nothing is out of date.
  • Moving expenses: The steps for moving an expense to a report do not change.

view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.95-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 failure ❌
🍎 iOS 🍎 failure ❌

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.

6 participants