extract useParticipantSubmission hook#87979
extract useParticipantSubmission hook#87979OlimpiaZurek wants to merge 4 commits intoExpensify:mainfrom
Conversation
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@marcaaron 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: e2df4745fa
ℹ️ 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 currentUserPersonalDetails = useCurrentUserPersonalDetails(); | ||
| const {policyForMovingExpenses} = usePolicyForMovingExpenses(); | ||
| const [draftTransactions] = useOptimisticDraftTransactions(initialTransaction); | ||
| const transactionIDs = draftTransactions?.map((transaction) => transaction.transactionID); |
There was a problem hiding this comment.
Memoize transaction IDs before subscribing to Onyx
transactionIDs is recomputed as a new array on every render and then fed into useTransactionsByID, whose selector is memoized on the transactionIDs reference; this makes the selector dependency change each render and triggers unnecessary resubscribe/reselect churn during participant-step interactions (e.g., typing/search updates). The previous implementation intentionally memoized IDs to avoid this hot-path overhead, so this regression can hurt the performance this refactor is trying to improve.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The useOptimisticDraftTransactions hook is compiled by React Compiler, so draftTransactions only gets a new reference on actual Onyx writes to COLLECTION.TRANSACTION_DRAFT . useTransactionsByID is also compiled with transactionsSelector cached on transactionIDs. On the participants step, the hot path is search (updates RAM_ONLY_IS_SEARCHING_FOR_REPORTS, not COLLECTION.TRANSACTION_DRAFT), so transactionIDs stays stable during search
Explanation of Change
Part of the ongoing IOURequestStepConfirmation decomposition, aimed at improving the create expense flow performance.
Extracts submission logic from
IOURequestStepParticipantsinto auseParticipantSubmissionhook, and fixes all React Compiler violations so the hook is fully memoized.What was extracted
IOURequestStepParticipants was 491 lines. The bulk of it was submission callbacks (
trackExpense,addParticipant,goToNextStep) that each maintained their own Onyx subscriptions inline, along with awaitForKeyboardDismisshelper and adataRefpattern to keep callback identities stable. The component now sits at 160 lines — route params, header title derivation, and JSX.The new useParticipantSubmission hook owns all of this: Onyx subscriptions, the dataRef pattern, and the three callbacks. It returns only {addParticipant, goToNextStep}.
Fixed Issues
$ #87959
PROPOSAL:
Tests
Offline tests
QA Steps
same as tests
// 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari