Skip to content

perf(Search): remove policyForMovingExpenses object from getSections memo#93432

Draft
BartekObudzinski wants to merge 2 commits into
Expensify:mainfrom
callstack-internal:perf/search-s3-policy-for-moving-expenses
Draft

perf(Search): remove policyForMovingExpenses object from getSections memo#93432
BartekObudzinski wants to merge 2 commits into
Expensify:mainfrom
callstack-internal:perf/search-s3-policy-for-moving-expenses

Conversation

@BartekObudzinski

Copy link
Copy Markdown
Contributor

Explanation of Change

This is a follow-up performance slice for the Search decomposition work. It removes the policyForMovingExpenses policy object from the screen-level getSections memo in src/components/Search/index.tsx.

Previously the full policy object was passed into getSections (call arg + useMemo dep array) and threaded down into getTransactionsSections in src/libs/SearchUIUtils.ts, where it was used only to compute shouldShowAttendees for unreported transactions. Because a policy object's reference changes on every unrelated update to that policy (e.g. Pusher pushes touching any field), the getSections memo was being invalidated and recomputed on changes that have nothing to do with what it actually needs.

getSections never needed the object: the only thing it derives from it is the boolean shouldShowAttendees(SUBMIT, policyForMovingExpenses), which gates whether attendees are populated on unreported transactions for the attendees sort columns. So instead of the object, the screen now passes the precomputed boolean isAttendeesEnabledForMovingPolicy (already computed once at the screen level). That boolean only flips when attendee tracking on the moving policy actually toggles, so the memo no longer recomputes on unrelated policy churn. Sort behavior is preserved exactly (the unreported branch resolves to the same value it did before).

Separately, the isAttendeesEnabledForMovingPolicy boolean used to be drilled from the Search screen down through SearchListBaseSearchListTransactionListItem to gate attendees display on the row. That drill (including a FlashList extraData entry that re-rendered every row when the moving policy changed) is removed. TransactionListItem already calls usePolicyForMovingExpenses() for sorting, so it now derives its own display gate from that same live hook. This keeps the row's attendees display reactive to the row's own live data without coupling it to the screen.

usePolicyForMovingExpenses() and policyForMovingExpensesID (used by the sort sections) are kept unchanged.

Performance

Removes policyForMovingExpenses (a policy object) from getSections, so the screen-level getSections memo no longer recomputes when unrelated fields of that policy change (Pusher pushes). The memo now depends on a stable boolean that only flips when attendee tracking on the moving policy toggles. Attendees display is now computed at the row from the row's own live policy data instead of being drilled from the screen, which also removes the moving-policy entry from the FlashList extraData array (it no longer invalidates every row on policy changes).

Fixed Issues

$ #92079
PROPOSAL:

Tests

  1. Have a workspace that is a Corporate policy with attendee tracking enabled, set as your active / moving-expenses policy.
  2. Create an unreported (Self DM / tracked) expense that has attendees on it.
  3. Open Search and run an Expenses search whose results include the unreported expense (e.g. status Unreported / All).
  4. Verify the attendees are shown on the unreported transaction row exactly as before this change.
  5. Switch the moving-expenses policy to one that is not Corporate / does not have attendee tracking enabled, then repeat steps 3-4 and verify attendees are no longer shown on the unreported row (unchanged behavior).
  6. Add the "Attendees" and "Total per attendee" columns and sort by each; verify the ordering of unreported transactions by attendee count is unchanged.
  7. Verify reported transactions (transactions that belong to a report) still show attendees based on their own report's policy.
  8. Verify no errors appear in the JS console.
  • Verify that no errors appear in the JS console

Offline tests

The change only relocates where an existing, already-loaded boolean is computed; it does not add any network request. Repeat the Tests above while offline and verify attendees render identically to the online behavior.

QA Steps

// 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 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 shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • 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.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
...ponents/Search/SearchList/BaseSearchList/index.tsx 0.00% <ø> (ø)
...archList/ListItem/TransactionGroupListExpanded.tsx 64.51% <ø> (ø)
src/components/Search/SearchList/ListItem/types.ts 100.00% <ø> (ø)
src/components/Search/SearchList/index.tsx 48.90% <ø> (-7.67%) ⬇️
src/libs/SearchUIUtils.ts 64.21% <100.00%> (-0.17%) ⬇️
src/components/Search/index.tsx 0.58% <0.00%> (-0.01%) ⬇️
.../SearchList/ListItem/TransactionListItem/index.tsx 0.00% <0.00%> (ø)
... and 206 files with indirect coverage changes

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.

1 participant