Migrate SearchAutocompleteList to useFilteredOptions#85922
Conversation
Replace useOptionsList context hook with useFilteredOptions to eliminate
unnecessary background recalculations on personal details/reports changes.
Key changes:
- Replace useOptionsList() with useFilteredOptions({enabled: true})
- Remove OptionsListStateContext dependency
- Update cold start telemetry to use isLoading from hook
- Add emptyOptionList fallback for null options
- Rename listOptions and isLoadingFullData to avoid conflicts
Part of OptionListContextProvider removal effort.
Fixes Expensify#82187
Use isLoading directly instead of areOptionsInitialized: !isLoading for clearer intent and simpler code in skeleton span attributes.
…-to-usefiltered-options
|
@shubham1206agra 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] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d749d89e90
ℹ️ 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".
| const taxRates = getAllTaxRates(policies); | ||
|
|
||
| const {options, areOptionsInitialized} = useOptionsList(); | ||
| const {options: listOptions, isLoading} = useFilteredOptions({enabled: true, searchTerm: autocompleteQueryValue, betas: betas ?? []}); |
There was a problem hiding this comment.
Debounce searchTerm passed to useFilteredOptions
Passing autocompleteQueryValue directly into useFilteredOptions here causes a full option-list rebuild on every keystroke; useFilteredOptions memoizes on searchTerm and calls createFilteredOptionList whenever it changes (src/hooks/useFilteredOptions.ts, lines 84-95), which reprocesses the reports/personal-details collections. In Search Router this turns normal typing into repeated full-list recomputation for high-traffic accounts, introducing visible input lag/jank compared to the previous flow that reused precomputed options and only filtered them.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@shubham1206agra, instead of passing searchTerm, should we pass a boolean flag so full option-list won't rebuild on every keystore? Wdyt
Replace searchTerm string parameter with isSearching boolean flag in useFilteredOptions and createFilteredOptionList to prevent full option-list rebuilds on every keystroke. The boolean flag only changes when transitioning between empty/non-empty states, instead of on every character typed. This fixes the P1 performance issue where passing autocompleteQueryValue directly caused visible input lag for high-traffic accounts. Addresses PR review comment #2965259765
|
PR doesn’t need product input as a migration PR. Unassigning and unsubscribing myself. |
| enabled: didScreenTransitionEnd, | ||
| betas: betas ?? [], | ||
| searchTerm: debouncedTextInputValue, | ||
| isSearching: !!debouncedTextInputValue, |
Trim debouncedSearchTerm and debouncedTextInputValue before converting to boolean to prevent whitespace-only strings from triggering search mode in NewChatPage and ShareTab. Addresses review feedback from PR Expensify#85922.
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.
|
…-to-usefiltered-options
Whitespace-only input (e.g., ' ') should not trigger search mode. This change makes the isSearching check consistent with other autocompleteQueryValue.trim() checks elsewhere in the component.
…-to-usefiltered-options
…clarity Renamed isLoading from useFilteredOptions to isLoadingOptions to be more specific about what is being loaded. Renamed isLoadingFullData to isLoading since it represents the main loading state that determines whether to show the skeleton view. This improves code readability by making it clear that: - isLoadingOptions: tracks whether filtered options are loading - isLoading: overall loading state (combines options loading + recent searches)
|
@shubham1206agra this PR is ready to review |
|
Sorry @hoangzinh, can you fix conflicts here? |
…-to-usefiltered-options
|
@shubham1206agra I fixed conflicts |
Reviewer Checklist
Screenshots/VideosScreen.Recording.2026-03-27.at.10.56.35.PM.mov |
…-to-usefiltered-options
The component was refactored to use useFilteredOptions instead of OptionListContextProvider, so the test mock needs to be updated to match the implementation. This fixes the failing test.
|
@mountiny, when you're back. Can you review this PR? TY |
|
Go go @mountiny |
mountiny
left a comment
There was a problem hiding this comment.
Sorry for the delay, thanks for the PR!
|
🚧 @mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.3.59-0 🚀
Bundle Size Analysis (Sentry): |
|
No help site changes are required. This PR is an internal refactoring that replaces the |
|
🚀 Deployed to production by https://github.com/AndrewGable in version: 9.3.59-4 🚀
|
Explanation of Change
Replace useOptionsList context hook with useFilteredOptions to eliminate unnecessary background recalculations on personal details/reports changes.
Part of OptionListContextProvider removal effort.
Fixed Issues
$ #82187
PROPOSAL:
Tests
Same as QA
Offline tests
Same as QA
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Screen.Recording.2026-03-20.at.18.05.40.mov
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-03-20.at.17.56.59.web.mov