Fix freeze when opening "Add approval workflow" on workspaces with many members#89268
Conversation
|
@abzokhattab 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: b7eeaa8123
ℹ️ 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".
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
There was a problem hiding this comment.
Pull request overview
This PR addresses a performance issue in the workspace approvals workflow UI where opening “Add approval workflow” could freeze on large workspaces due to repeated full-employee-list processing.
Changes:
- Hoists
getMemberAccountIDsForWorkspace(policy?.employeeList)so it’s computed once per render instead of once per member. - Reuses the computed email→accountID map in both the
useEffectselected-members sync and theavailableMembersconstruction.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }), | ||
| ); | ||
| }, [approvalWorkflow?.members, policy?.employeeList, policy?.owner, translate, icons.FallbackAvatar]); | ||
| }, [approvalWorkflow?.members, policy?.employeeList, policy?.owner, policyMemberEmailsToAccountIDs, translate, icons.FallbackAvatar]); |
|
@MelvinBot can you please create a dedicated issue for this pull request and assign @mountiny and @TMisiukiewicz and @abzokhattab. Make it with Daily, Bug, Reviewing labels |
|
Created dedicated issue: #89270 Assigned to |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2026-04-30.at.18.11.27.movAndroid: mWeb ChromeScreen.Recording.2026-04-30.at.18.12.17.moviOS: HybridAppScreen.Recording.2026-04-30.at.18.11.27.moviOS: mWeb SafariScreen.Recording.2026-04-30.at.18.12.17.movMacOS: Chrome / SafariScreen.Recording.2026-04-30.at.18.10.20.mov |
|
🚧 @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.66-0 🚀
|
|
No help site changes are needed for this PR. It's a performance optimization that hoists |
Explanation of Change
getMemberAccountIDsForWorkspace(policy?.employeeList)was being called inside two separate.map()callbacks — one inside auseEffectand one in theavailableMembersmap. This function iterates the entire workspaceemployeeListand performs a personal-detail lookup per email, so calling it inside a.map()over the same list created O(N²) work. On a workspace with a few hundred members, pressing "Add approval workflow" froze the app for roughly a minute.The fix hoists the call to the component body so it runs once per render instead of once per member. React Compiler memoizes it automatically — no
useMemoneeded (and per project coding rules,useMemo/useCallback/React.memoare forbidden). No behavior change: same data, just computed once instead of N times.Fixed Issues
$ #89270
PROPOSAL:
Tests
Offline tests
N/A
QA Steps
Same as tests
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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari