Skip to content

[CP Staging] fix: refresh Search after an expense moves report or a report changes workspace - #98752

Merged
mountiny merged 2 commits into
Expensify:mainfrom
callstack-internal:fix/search-blocker-regressions
Aug 17, 2026
Merged

[CP Staging] fix: refresh Search after an expense moves report or a report changes workspace#98752
mountiny merged 2 commits into
Expensify:mainfrom
callstack-internal:fix/search-blocker-regressions

Conversation

@BartekObudzinski

@BartekObudzinski BartekObudzinski commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Both blockers came from one removal in PR 98305, which is currently on main through the reland PR 98558. Before 98305 the trigger in useSearchHighlightAndScroll was (!isChat && hasTransactionsIDsChange) || hasReportActionsIDsChange, so hasReportActionsIDsChange applied to every search type. Any report action anywhere in the account refetched Search, which is the duplicate traffic reported in issue 98048, and it is also what made both of these flows work by accident. Restoring that condition is not an option, so each flow gets its own correct signal.

98698, expenses count does not update after adding an expense to a report. Moving an expense replaces the transaction object because reportID changes, but hasChangedTransactionInSearchResults only asked whether that transaction's own ID is in the results. In the repro the expense sits in a self DM that the Reports view does not show, so the answer was no and nothing refetched, while the report row still owes its expense count and total to the server computed snapshot. The check now also counts a transaction whose reportID moved into or out of a report the results display, which is a single lookup of the report_<id> key already present in the snapshot. This lives in the hook rather than the call site because changeTransactionsReport is called from many places across the app, and all of them were equally stale.

98723, report stays in the old workspace filter. Here there is no transaction side signal at all. buildOptimisticChangePolicyData sets report.policyID optimistically, writes only the policy object into the snapshot and never the report row, and touches transactions only when the destination currency differs. A filtered snapshot therefore keeps a report that no longer belongs to it, and no local patch can decide whether the row still matches the query, only the server can. So selectPolicy now calls the existing refreshSearchAfterReportAction from @libs/SearchRefreshUtils on all three exit paths (IOU, invite submitter, plain change). Other call sites in the codebase already follow that pattern, including useLifecycleActions and useSelectionModePayment. It is not done in the hook because the signal is report.policyID and Search/index.tsx does not subscribe to the REPORT collection. Adding a whole collection REPORT subscription to that component would be a performance regression in a hot path.

This also unblocks the open revert PR 98728, which would otherwise revert the reland again.

Fixed Issues

$ #98698
$ #98723
PROPOSAL:

Tests

test steps described in linked tickets

  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

98698:
1.Action Performed:
2.Go to staging.new.expensify.com
3.Create an empty report in workspace chat.
4.Create an expense in self DM.
5.Go to Spend > Reports.
6.Select the report via checkbox.
7.Open the report.
8.Click Add expense > Add existing expense.
9.Select self DM expense > Add to report.
10.Close the report.

98723:
Preconditions: User has an unvalidated account, has multiple workspaces, and has multiple reports in Workspace 1

1.Open the NewDot app
2.Navigate to the Spend - Report - Filter - Workspace 1
3.Select any report - More - Change Workspace - Select another Workspace (like Workspace 4)
4.Report move to the new Workspace and is no longer displayed in the filter anymore, like Prod

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • 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 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 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

@BartekObudzinski

Copy link
Copy Markdown
Contributor Author

#98723

98723.mov

@BartekObudzinski

Copy link
Copy Markdown
Contributor Author

#98698

98723.mov

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
src/hooks/useSearchHighlightAndScroll.ts 91.02% <100.00%> (+0.23%) ⬆️
src/pages/DynamicReportChangeWorkspacePage.tsx 0.00% <0.00%> (ø)
... and 30 files with indirect coverage changes

@BartekObudzinski
BartekObudzinski marked this pull request as ready for review August 17, 2026 08:08
@BartekObudzinski
BartekObudzinski requested review from a team as code owners August 17, 2026 08:08
@melvin-bot
melvin-bot Bot requested review from QichenZhu and joekaufmanexpensify and removed request for a team August 17, 2026 08:09
@melvin-bot

melvin-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

@QichenZhu 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]

@melvin-bot
melvin-bot Bot removed the request for review from a team August 17, 2026 08:09
@BartekObudzinski

Copy link
Copy Markdown
Contributor Author

@codex review

@mountiny mountiny changed the title fix: refresh Search after an expense moves report or a report changes workspace [CP Staging] fix: refresh Search after an expense moves report or a report changes workspace Aug 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

This comment has been minimized.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bc7b5d00eb

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/pages/DynamicReportChangeWorkspacePage.tsx
@QichenZhu

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
    https://expensify.slack.com/archives/C01GTK53T8Q/p1786700297085539
  • I verified proper code patterns were followed (see Reviewing the code)
    • 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
    • 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
    • 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 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
Screen.Recording.2026-08-17.at.8.49.14.PM.mov
Screen.Recording.2026-08-17.at.8.50.13.PM.mov
Android: mWeb Chrome
Screen.Recording.2026-08-17.at.8.51.34.PM.mov
Screen.Recording.2026-08-17.at.8.52.20.PM.mov
iOS: HybridApp
Screen.Recording.2026-08-17.at.8.41.21.PM.mov
Screen.Recording.2026-08-17.at.8.45.26.PM.mov
iOS: mWeb Safari
Screen.Recording.2026-08-17.at.8.54.21.PM.mov
Screen.Recording.2026-08-17.at.8.55.12.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-08-17.at.8.58.14.PM.mov
Screen.Recording.2026-08-17.at.8.58.47.PM.mov

@QichenZhu

Copy link
Copy Markdown
Contributor

Offline mode doesn't work for either issue, which is expected.

Screen.Recording.2026-08-17.at.8.59.45.PM.mov
Screen.Recording.2026-08-17.at.9.00.08.PM.mov

@QichenZhu QichenZhu 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.

Thanks!

@melvin-bot
melvin-bot Bot requested review from mountiny and youssef-lr August 17, 2026 09:10

@mountiny mountiny 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.

Thanks for a quick fix

Comment on lines +116 to +128
const {currentSearchQueryJSON, currentSearchKey} = useSearchQueryContext();
const {currentSearchResults} = useSearchResultsContext();
const shouldCalculateTotals = useSearchShouldCalculateTotals(currentSearchKey, currentSearchQueryJSON?.hash, true);

// The snapshot keeps the report row after a workspace change, and only the server can tell whether it still matches the query.
const refreshSearch = () => {
refreshSearchAfterReportAction({
currentSearchQueryJSON,
currentSearchKey,
shouldCalculateTotals,
isOffline,
isLoading: !!currentSearchResults?.search?.isLoading,
});

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.

Is this not going to lead to many extra Search calls?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nope, it's one call per workspace pick. It only runs when you tap a row in that list, and if a search for the same hash and offset is already in flight, search method throws it away anyway

@mountiny
mountiny merged commit f1ba262 into Expensify:main Aug 17, 2026
42 of 49 checks passed
OSBotify pushed a commit that referenced this pull request Aug 17, 2026
…regressions

[CP Staging] fix: refresh Search after an expense moves report or a report changes workspace

(cherry picked from commit f1ba262)

(cherry-picked to staging by mountiny)
@github-actions

Copy link
Copy Markdown
Contributor

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

@OSBotify OSBotify added the CP Staging marks PRs that have been CP'd to staging label Aug 17, 2026
@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

🔁 Filed a Staging retest request for deploy blockers #98698, #98723 after this PR was cherry-picked to staging.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Cherry-picked to staging by https://github.com/mountiny in version: 9.4.54-2 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

Help site review: no changes required

I reviewed the changes in this PR and no updates to the help site (App/docs/articles) are needed, so I did not open a docs PR.

Why: This PR is an internal bug fix to Search's refresh logic. It restores already-expected behavior rather than adding or changing any user-facing feature, workflow, screen, or label:

  • useSearchHighlightAndScroll.ts — now also refetches Search when a transaction's reportID moves into or out of a report the current results display, so an expense's count/total updates after it's moved (issue 98698).
  • DynamicReportChangeWorkspacePage.tsx — calls refreshSearchAfterReportAction on all three exit paths so a report leaves the old workspace filter after its workspace changes (issue 98723).
  • useSearchHighlightAndScrollTest.ts — unit tests for the above.

The user-facing flows involved (moving an expense between reports, changing a report's workspace, and filtering Search) are already documented and behave exactly as the existing articles describe — e.g. Managing Expenses in a Report and Use Search Operators to Filter and Analyze. This fix only makes the UI correctly reflect that documented behavior, so none of those articles need editing.

@BartekObudzinski, please confirm this assessment. Since no help site changes are required, there is no linked help site PR to mark Ready for review — if you believe a documented behavior did change and warrants an article update, reply with the specific article and I'll draft it.

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

Labels

CP Staging marks PRs that have been CP'd to staging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants