Skip to content

Route Search previews through the shared LHN alternate text pipeline - #99062

Closed
sosek108 wants to merge 41 commits into
Expensify:mainfrom
callstack-internal:fix/search-adopt-lhn-alternate-text
Closed

sosek108 wants to merge 41 commits into
Expensify:mainfrom
callstack-internal:fix/search-adopt-lhn-alternate-text

Conversation

@sosek108

@sosek108 sosek108 commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Makes SearchRouter / Search row subtitles (alternateText) identical to LHN by construction.

A new test file tests/unit/LhnSearchPreviewParityTest.ts will assert strict LHN === Search equality on identical Onyx state.

Fixed Issues

$ #98958
PROPOSAL:

Tests

  1. npx jest tests/unit/LhnSearchPreviewParityTest.ts tests/unit/SidebarUtilsTest.ts tests/unit/OptionsListUtilsTest.tsx
  2. Use large account with a lot of reports
  3. Go through LHN and Search bar (CMD+K or magnifying glass icon) and compare subtitle of entries. These should be same for every entry

Offline tests

N/A

QA Steps

  1. Use large account with a lot of reports
  2. Go through LHN and Search bar (CMD+K or magnifying glass icon) and compare subtitle of entries. These should be same for every entry

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
Nagranie.z.ekranu.2026-09-1.o.12.49.39.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
Nagranie.z.ekranu.2026-09-1.o.12.43.28.mov

…hn-alternate-text

# Conflicts:
#	src/libs/OptionsListUtils/index.ts
#	src/libs/ReportAlternateTextUtils.ts
…hn-alternate-text

# Conflicts:
#	tests/ui/WorkspaceCompanyCardPageEmptyStateTest.tsx
@codecov

codecov Bot commented Sep 1, 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 Δ
...c/components/CurrencyListContextProvider/index.tsx 100.00% <100.00%> (ø)
src/components/LocaleContextProvider.tsx 85.48% <100.00%> (-0.24%) ⬇️
.../components/Search/FilterComponents/InSelector.tsx 90.00% <100.00%> (+0.52%) ⬆️
src/components/Search/SearchAutocompleteList.tsx 88.68% <100.00%> (+0.26%) ⬆️
...rc/components/Search/SearchRouter/SearchRouter.tsx 72.25% <100.00%> (+0.48%) ⬆️
.../Search/SearchRouter/SearchRouterOptionsWarmer.tsx 96.66% <100.00%> (ø)
src/hooks/useAutocompleteSuggestions.ts 73.91% <100.00%> (+0.64%) ⬆️
src/hooks/useFilteredOptions.ts 86.66% <100.00%> (+2.66%) ⬆️
src/hooks/useGetExpensifyCardFromReportAction.ts 100.00% <100.00%> (ø)
src/hooks/useSearchSelector/base.ts 88.28% <100.00%> (+0.47%) ⬆️
... and 10 more
... and 7 files with indirect coverage changes

@sosek108

sosek108 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot review
@codex review

@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: 5f1c093e34

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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

Copy link
Copy Markdown
Contributor

Reviewed the diff. The refactor direction is right — collapsing getChatPreviewParts into the shared getReportAlternateText removes a whole class of drift. Three things to look at before merge, one of which undercuts the "identical by construction" claim.

1. Search and LHN still resolve lastAction with different algorithms

Everything downstream keys off lastAction, so parity holds only where the two resolvers agree — and they don't always.

  • LHN: OptionRowLHNData.tsx:105 calls getLastVisibleActionIncludingTransactionThread, which takes the newest visible action on the parent and the newest on the thread, then compares created.
  • Search: ReportAlternateTextUtils.ts:425-431 takes the first match in the pre-combined sortedActions[reportID] array.

Those differ because getCombinedReportActions drops IOU-create actions from the combined list: ReportActionsUtils.ts:895-898. isReportActionVisibleAsLastAction keeps them (:1436), so LHN sees them.

Failure case: a one-transaction expense report submitted with no follow-up comment. The parent's newest visible action is the IOU-create action and the thread only has CREATED. LHN resolves lastAction to the IOU action; Search's find skips it (filtered out of the combined array) and lands on an older action, or undefined. Different subtitle.

The cheap fix is to have resolveLastActionContext always use getLastVisibleActionIncludingTransactionThread — it's already the else branch — or move LHN onto the sortedActions path. One shared resolver is what makes the claim structural rather than incidental. Either way, please add a one-transaction-report case to LhnSearchPreviewParityTest.ts; the current suite doesn't cover one.

2. invoiceReceiverPolicy is declared but never supplied

OptionsListUtils/index.ts:237 adds it to GetAlternateTextConfig and :341 forwards it, but no caller passes it — it is always undefined. The PR encodes the resulting mismatch as an expected result (should diverge for empty invoice room…).

This looks closeable rather than permanent: prepareReportOptionsForDisplay already has policiesCollection in scope and already resolves policy from it, so report.invoiceReceiver.policyID → one more lookup gets you the rest of the way. Worth doing here, otherwise the test locks in a gap that the PR title says doesn't exist.

3. Dead plumbing — about 60 lines

cardList, workspaceCardList, localeCompare, formatPhoneNumber, and convertToDisplayString are threaded through createOption, createOptionFromReport, and processReport, but every call site of those three has showChatPreviewLine false, so they can't reach the branch that reads them:

  • processReport → createOption passes no config, and createFilteredOptionList never forwards localeCompare/formatPhoneNumber/convertToDisplayString anyway.
  • SearchRouter and InSelector call createOptionFromReport with config: {showPersonalDetails} only.
  • The InSelector getAlternateText call passes {} as config, so its nine new arguments are inert.

convertToDisplayString is on six type definitions and supplied by zero components. The only live consumer is prepareReportOptionsForDisplay. Trimming this keeps the surface honest about which inputs actually matter.

Minor

Testing note

I tried to confirm the subtitle parity in a browser session, but the web session rendered a blank page (0 DOM nodes, dev server healthy and serving the bundle) and never reached Home, so I could not compare the two lists visually. The findings above are from reading the code. CI is green apart from Check independent approval.


view run

@sosek108

sosek108 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

All three findings from my last pass are fixed at 6bc6cbaa, and CI is green apart from Check independent approval. Two things left, neither a blocker.

What got resolved

  • resolveLastActionContext now always calls getLastVisibleActionIncludingTransactionThread — the same resolver LHN uses — and the new should match for a one-transaction expense report whose newest action is the IOU create action test covers exactly the case that would have diverged.
  • invoiceReceiverPolicy is now resolved in prepareReportOptionsForDisplay with the same report-then-parent precedence as LHNOptionsList.tsx:77-84, and the invoice test now asserts equality instead of divergence.
  • The dead cardList / workspaceCardList / localeCompare / formatPhoneNumber / convertToDisplayString plumbing is gone, and Parser.htmlToText is back in the missing-report fallback.

1. The "clean up comment" commit stripped rationale that should stay

4d211eb removed roughly twenty comments. Most were restating the code and are fine to lose, but a few documented decisions that aren't recoverable from reading it:

  • ReportAlternateTextUtils.ts:1231-1232 — the || here sits directly under an eslint-disable for prefer-nullish-coalescing. The deleted comment explained that an empty precomputed string means "not computed yet," so ?? would silently kill the recompute fallback. Without it the next person reads a suppressed lint rule with no reason and switches it.
  • OptionsListUtils/index.ts:257-259 — the module-scoped collator looks like avoidable global state until you know new Intl.Collator loads locale data and can't be built per comparison inside a sort.
  • OptionsListUtils/index.ts:324 — privateIsArchived: !!isReportArchived passes one value for two distinct-looking parameters. The deleted comment explained both derive from the same NVP.
  • ReportAlternateTextUtils.ts:1651-1655 — the two-Onyx-key lookup in getExpensifyCardFromReportAction is not guessable; the Travel Billing key variant needs the note.

The author checklist asks for comments explaining "why" on code that isn't self-explanatory. These four qualify.

2. Preview resolution got slower per row — worth a manual sanity check

Moving to the LHN resolver was the right correctness call, but it changed the cost profile. The deleted getChatPreviewParts used sortedActions[reportID].find(...) on the pre-sorted derived array, which exits at the first visible action. resolveLastActionContext now runs getLastVisibleActionIncludingTransactionThread, which does two full Object.values scans over the raw action maps with an isNewerReportAction comparison per entry, and it runs unconditionally — before the || short-circuit that skips getLastMessageTextForReport.

That happens once per option inside prepareReportOptionsForDisplay, which re-runs on every keystroke in the search router. sortedActions is still threaded into getAlternateText for other uses, so the sorted array is right there if you want the cheap path on both surfaces.

baseline-perf-tests and branch-perf-tests both pass, so nothing is flagged. But those don't exercise the router's keystroke path, and your own test plan calls for a high-traffic account — worth typing into the router on one and confirming it still feels instant.

Web verification

🤖 Web test steps verification results: ✅ pass

Subtitle text matched between the LHN and the search router for the one chat present in both lists. Coverage is thin: the test account is fresh and has a single conversation, so this confirms the pipeline runs and produces identical output, not that the edge cases match.

Search router with empty query showing recent chats

Step Status
LHN chat list subtitle capturedOne row, "Expensify Concierge", subtitle "Welcome to Expensify Hi! I'm Concierge. I can help you get set up, answer questions, and update your expenses with a quick chat. What can I do for you today?"
LHN Inbox showing Concierge chat row with subtitle
✅
Search router opened with empty query"Recent chats" showed the self-DM and Concierge, both with non-empty subtitles
Search router with empty query showing recent chats
✅
Subtitle identical between the two surfacesConcierge is the only chat in both lists; its subtitle string matched exactly
✅
No blank subtitle in the search routerBoth rows rendered subtitle text
✅

view run

@sosek108
sosek108 marked this pull request as ready for review September 4, 2026 08:20
@sosek108
sosek108 requested review from a team as code owners September 4, 2026 08:20
@melvin-bot
melvin-bot Bot requested review from thelullabyy and removed request for a team September 4, 2026 08:20

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

Nice cleanup — routing Search through getReportAlternateText is the right call, and passing the already computed reportMetadata and participantPersonalDetailListExcludeCurrentUser down from SidebarUtils.getOptionData removes real duplicated work per LHN row.

One request, plus a few non-blocking notes inline.

Please restore tests/unit/ReportAlternateTextParityTest.ts and its snapshot

I ran the deleted suite against this branch: 145 of 145 snapshots pass unchanged. Keeping it costs nothing and CI stays green:

git checkout dc10c9e0a0dac855412530ec08a68ac6798ecc05 -- tests/unit/ReportAlternateTextParityTest.ts tests/unit/__snapshots__/ReportAlternateTextParityTest.ts.snap

It pins the expected string for 115 action types. Only 25 of those appear in SidebarUtilsTest.ts, so 90 action types lose their only pinned expected output. LhnSearchPreviewParityTest asserts searchText === lhnText plus one toContain, so a change that moves both surfaces together is invisible to it.

That matters here specifically because this PR changes getLastActorDisplayNameFromLastVisibleActions to use getLastVisibleActionIncludingTransactionThread, and the LHN goes through that same function — the snapshot is the evidence that no LHN output shifted. The two suites cover different axes, so keep both.

Verified locally on c16419e

Check Result
tsc --noEmit clean
LhnSearchPreviewParityTest + OptionsListUtilsTest + SidebarUtilsTest 574 passing
useSearchSelectorTest + useAutocompleteSuggestions + InSelectorTest 56 passing
eslint on changed files only pre-existing seatbelt patterns, nothing on new lines

Minor: the PR body still carries the // TODO: These must be filled out line under QA Steps.

formatPhoneNumber: formatPhoneNumber ?? formatPhoneNumberPhoneUtils,
dateFnsLocale,
convertToDisplayString,
convertToDisplayStringWithoutCurrency: convertToDisplayStringWithoutCurrency ?? fallbackConvertToDisplayStringWithoutCurrency,

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.

convertToDisplayStringWithoutCurrency is unreachable, so this fallback is always the implementation.

It is declared on GetAlternateTextConfig (line 251) but not on GetOptionsConfig (types.ts), SearchOptionsConfig, or prepareReportOptionsForDisplay's config. getAlternateText is only reached from createOption, prepareReportOptionsForDisplay, and InSelector, and none of them can supply it.

fallbackConvertToDisplayStringWithoutCurrency (line 283) also duplicates CurrencyListContextProvider/index.tsx lines 58-80 verbatim, comments included. Unlike sortedActions and currentUserAccountID, this param has neither a caller nor a TODO pointing at a refactor issue.

Either thread it down from useCurrencyListActions() alongside convertToDisplayString, or drop the param and the fallback.

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.

The params thread is done and fallback duplicated code is gone.

It added some files to the diff as the change touched at least 7 callers

Comment thread src/libs/OptionsListUtils/index.ts Outdated
const locale = IntlStore.getCurrentLocale();
if (!fallbackCollator || fallbackCollatorLocale !== locale) {
fallbackCollatorLocale = locale;
fallbackCollator = new Intl.Collator(locale, {usage: 'sort', sensitivity: 'variant', numeric: true, caseFirst: 'upper'});

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.

This is the fourth copy of these collator options in the codebase:

  • LocaleContextProvider.tsx:97 (COLLATOR_OPTIONS)
  • ReportNameUtils.ts:269
  • SearchQueryUtils.ts:556

Worth exporting one shared helper so they cannot drift apart.

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.

Extracted Collator to CollatorUtils

Comment thread src/pages/Share/ShareTab.tsx Outdated
policyCollection: allPolicies,
personalDetails,
sortedActions,
cardList,

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.

cardList and workspaceCardList cannot be read on this path.

Line 84 sets isUsedInChatFinder: false, which makes showChatPreviewLine false inside getSearchOptions, and both values are only consumed inside that branch (OptionsListUtils/index.ts:347). The getAlternateText(report, {}, ...) call in InSelector is the same story.

Safe to drop these two lines along with the useCardList() / useWorkspaceCardList() calls on lines 60-61.

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.

Droped both lists

Comment thread src/libs/OptionsListUtils/index.ts Outdated
const resolvedCurrentUserAccountID = currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID;
const oneTransactionThreadReportID = transactionThreadIDs?.[report.reportID];
const {lastAction, lastActionReport, movedFromReport, movedToReport} = resolveLastActionContext(report, isReportArchived, visibleReportActionsData, oneTransactionThreadReportID);
const card = isCardIssuedAction(lastAction) ? getExpensifyCardFromReportAction({reportAction: lastAction, policy, cardList, workspaceCardList}) : undefined;

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.

Worth a Reassure run before merge.

The LHN pays this resolution once per visible row (roughly 20), but prepareReportOptionsForDisplay is not memoised the way createFilteredOptionList is, so Search now runs the full getReportAlternateText per option up to maxElements.

tests/perf-test/OptionsListUtils.perf-test.ts and tests/perf-test/SearchRouter.perf-test.tsx both cover this path.

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.

Good call. Two findings.

The two suites you named don't cover this path. createRandomReport (tests/utils/collections/reports.ts:13) sets no participants and no chatType, so processReport (OptionsListUtils/index.ts:988) drops all 5000 fixture reports before createOption. Both files use that factory, so getLastMessageTextForReport and getReportAlternateText never run in either. Local Reassure also can't resolve deltas this size: main vs main reported "significant" regressions up to +55%.

So I added covering scenarios (tests/perf-test/OptionsListChatPreview.perf-test.ts) — participant-bearing reports with report actions, deterministic fixtures, showChatPreviewLine: true, two result caps. Min of 4 interleaved runs per state:

Scenario main this branch branch + memo
getValidOptions previews, cap 20 26.74 ms 28.56 ms (+6.8%) 25.09 ms (−6.2%)
getValidOptions previews, cap 100 29.88 ms 34.82 ms (+16.5%) 24.94 ms (−16.5%)
createFilteredOptionList (build) 26.44 ms 21.78 ms (−17.6%) 21.49 ms (−18.7%)

Your read was right — the preview cost is real and scales with maxElements. The build path is ~18% faster because threading lastActions/transactionThreadIDs through createOption drops the per-report Onyx rescan.

Memo added: prepareReportOptionsForDisplay caches the preview per report, dropping the cache when any input feeding it changes identity (same shape as the createFilteredOptionList cache). One prerequisite — both it and getValidOptions defaulted visibleReportActionsData to a fresh {}, which the share-destination caller doesn't pass, so the guard invalidated every call (0 hits / 1320 misses); pointing both at the existing EMPTY_VISIBLE_REPORT_ACTIONS gives 1220 hits / 100 misses.

Caveat: those means are warm-cache dominated (1 cold + 10 warm), so the first call after a guarded input changes still costs the pre-memo amount.

@sosek108 sosek108 left a comment

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.

@mountiny I've replied to your comments. I've also reintroduced Snapshot/parity tests

formatPhoneNumber: formatPhoneNumber ?? formatPhoneNumberPhoneUtils,
dateFnsLocale,
convertToDisplayString,
convertToDisplayStringWithoutCurrency: convertToDisplayStringWithoutCurrency ?? fallbackConvertToDisplayStringWithoutCurrency,

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.

The params thread is done and fallback duplicated code is gone.

It added some files to the diff as the change touched at least 7 callers

Comment thread src/libs/OptionsListUtils/index.ts Outdated
const locale = IntlStore.getCurrentLocale();
if (!fallbackCollator || fallbackCollatorLocale !== locale) {
fallbackCollatorLocale = locale;
fallbackCollator = new Intl.Collator(locale, {usage: 'sort', sensitivity: 'variant', numeric: true, caseFirst: 'upper'});

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.

Extracted Collator to CollatorUtils

Comment thread src/pages/Share/ShareTab.tsx Outdated
policyCollection: allPolicies,
personalDetails,
sortedActions,
cardList,

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.

Droped both lists

Comment thread src/libs/OptionsListUtils/index.ts Outdated
const resolvedCurrentUserAccountID = currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID;
const oneTransactionThreadReportID = transactionThreadIDs?.[report.reportID];
const {lastAction, lastActionReport, movedFromReport, movedToReport} = resolveLastActionContext(report, isReportArchived, visibleReportActionsData, oneTransactionThreadReportID);
const card = isCardIssuedAction(lastAction) ? getExpensifyCardFromReportAction({reportAction: lastAction, policy, cardList, workspaceCardList}) : undefined;

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.

Good call. Two findings.

The two suites you named don't cover this path. createRandomReport (tests/utils/collections/reports.ts:13) sets no participants and no chatType, so processReport (OptionsListUtils/index.ts:988) drops all 5000 fixture reports before createOption. Both files use that factory, so getLastMessageTextForReport and getReportAlternateText never run in either. Local Reassure also can't resolve deltas this size: main vs main reported "significant" regressions up to +55%.

So I added covering scenarios (tests/perf-test/OptionsListChatPreview.perf-test.ts) — participant-bearing reports with report actions, deterministic fixtures, showChatPreviewLine: true, two result caps. Min of 4 interleaved runs per state:

Scenario main this branch branch + memo
getValidOptions previews, cap 20 26.74 ms 28.56 ms (+6.8%) 25.09 ms (−6.2%)
getValidOptions previews, cap 100 29.88 ms 34.82 ms (+16.5%) 24.94 ms (−16.5%)
createFilteredOptionList (build) 26.44 ms 21.78 ms (−17.6%) 21.49 ms (−18.7%)

Your read was right — the preview cost is real and scales with maxElements. The build path is ~18% faster because threading lastActions/transactionThreadIDs through createOption drops the per-report Onyx rescan.

Memo added: prepareReportOptionsForDisplay caches the preview per report, dropping the cache when any input feeding it changes identity (same shape as the createFilteredOptionList cache). One prerequisite — both it and getValidOptions defaulted visibleReportActionsData to a fresh {}, which the share-destination caller doesn't pass, so the guard invalidated every call (0 hits / 1320 misses); pointing both at the existing EMPTY_VISIBLE_REPORT_ACTIONS gives 1220 hits / 100 misses.

Caveat: those means are warm-cache dominated (1 cold + 10 warm), so the first call after a guarded input changes still costs the pre-memo amount.

@sosek108
sosek108 force-pushed the fix/search-adopt-lhn-alternate-text branch from 68cf36f to dc77b33 Compare September 10, 2026 11:11
@sosek108

Copy link
Copy Markdown
Contributor Author

https://expensify.slack.com/archives/C08CZDJFJ77/p1789120225042869?thread_ts=1787056222.560989&cid=C08CZDJFJ77

Decided to split this one into five smaller:

PR 1 — Extract CollatorUtils
Files: 4 | +31 / −5

PR 2 — Generalize convertToDisplayStringWithoutCurrency for locale
Files: 2 | +23 / −26

PR 3 — Extract getExpensifyCardFromReportAction
Files: 2 | ~+32 / −19

PR 4 — useSortedActions -> useSortedReportActionsData
Files: ~10 | ~+32 / −23

PR 5 — #99062 replacement. This ships the core issued logic and tests
Files: ~21 (13 src + 8 test) | ~+2780 / −780  (src ~+796 / −411)

SEQUENCE
1,2,3,4 - should be straight forward and mergable in parallel
5 - can be merged after 1-4

Marking this one as Draft

@mountiny

Copy link
Copy Markdown
Contributor

I think we can close this now as we we are breaking it up to smaller prs

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.

5 participants