Repository navigation
Perf: Make SearchAutocompleteList compilable by React Compiler - #84502
Conversation
|
@aimane-chnaif 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: 0acf3dc061
ℹ️ 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".
| startSpan(CONST.TELEMETRY.SPAN_SEARCH_ROUTER_LIST_RENDER, { | ||
| name: CONST.TELEMETRY.SPAN_SEARCH_ROUTER_LIST_RENDER, | ||
| op: 'ui.render', | ||
| parentSpan: getSpan(CONST.TELEMETRY.SPAN_OPEN_SEARCH_ROUTER), | ||
| }); |
There was a problem hiding this comment.
Cancel list-render span when router closes before list mounts
Starting SearchRouter.ListRender inside openSearchRouter begins the span before SearchAutocompleteList is mounted. On native, DeferredAutocompleteList (src/components/Search/DeferredSearchAutocompleteList/index.native.tsx) delays mounting the actual list behind a skeleton/transition, so if the router is closed during that delay, the unmount cleanup in SearchAutocompleteList never runs and this span stays active until a later open cancels it. This skews telemetry for quick-open/quick-close flows and leaves stale active spans, so this path needs an explicit cancel on close (or the span should start only when the list actually mounts).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch — this is a real behavioral difference introduced by this PR.
Before (on main): The LIST_RENDER span was started during the render phase of SearchAutocompleteList itself, so the component was already mounted and its cleanup effect (cancelSpan(LIST_RENDER)) would always run on unmount.
After (this PR): The span now starts in the SearchRouterContext callback before the list mounts. On native, DeferredSearchAutocompleteList delays mounting behind a skeleton/transition, so if the user closes the router during that delay, SearchAutocompleteList never mounts and the cleanup effect never runs — leaving a stale span.
Fix: Added cancelSpan(CONST.TELEMETRY.SPAN_SEARCH_ROUTER_LIST_RENDER) to closeSearchRouter so the span is properly canceled regardless of whether the list mounted. This is the same pattern already used there for SPAN_SEARCH_PAGE_VISIBLE. Updated in f7c892f.
Move the LIST_RENDER span start from render-phase ref mutations in SearchAutocompleteList into the existing callbacks in SearchRouterContext (both button and keyboard paths), following the same callback/onLayout pattern used by ManualOpenReport and other telemetry flows. Remove the COMPUTE_OPTIONS span since render-phase computation timing cannot be measured without violating React Compiler's purity rules. The gap between sub-spans in Sentry naturally captures this overhead. Made-with: Cursor
0acf3dc to
f7c892f
Compare
|
I think this should do it and ensure the component is fine with react compiler |
|
PR doesn’t need product input as a performance PR. Unassigning and unsubscribing myself. |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppios.moviOS: mWeb SafariMacOS: Chrome / Safariweb.mov |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
|
🚧 @nkuoch 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/nkuoch in version: 9.3.35-0 🚀
|
|
@mountiny Can we skip 6 and 7 steps as we unable to check Sentry? |
|
@izarutskaya correct! |
|
🚀 Deployed to production by https://github.com/luacmartins in version: 9.3.35-1 🚀
|
Explanation of Change
PR #83076 added diagnostic sub-spans to
ManualOpenSearchRouterbut introduced two blocks inSearchAutocompleteListthat read/writeref.currentduring render, breaking React Compiler compatibility. These were the only twoeslint-disable-next-line react-hooks/refsviolations in the entiresrc/directory.This PR fixes the React Compiler violation by using the same patterns already established across the codebase:
SearchRouter.ListRenderspan start from render-phase ref mutations inSearchAutocompleteListinto the existing callbacks inSearchRouterContext(both button and keyboard trigger paths). This follows the same callback-start/onLayout-end pattern used byManualOpenReport(OptionRowLHN.onPress→ReportActionsView.onLayout) and all other telemetry flows.SearchRouter.ComputeOptionsspan since render-phase computation timing cannot be measured without violating React Compiler's purity rules. The gap between sub-spans in Sentry naturally captures the JS computation and React scheduling overhead, as the original PR description noted.eslint-disable-next-line react-hooks/refscomments.cancelSpan(LIST_RENDER)tocloseSearchRouterto handle the case where the router is closed beforeSearchAutocompleteListmounts (e.g. on native withDeferredSearchAutocompleteList).startListRenderSpan()helper to eliminate code duplication, following the same pattern as the existingstartSearchRouterOpenSpan().Both files pass the React Compiler compliance check after this change:
Fixed Issues
$ #79353
Tests
Offline tests
QA Steps
ManualOpenSearchRouterspans — verify child spans (SearchRouter.ModalCloseWait,SearchRouter.ListRender) appear nested under the parent spancold_startandtriggerattributes are present on the parent spanPR 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari