You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-04-30] [Due for payment 2026-04-28] [$250] Refactor: extract MoneyReportHeader actions into hooks and components #87937
MoneyReportHeader had grown to ~2400+ lines, mixing UI with business logic (hold menus, primary actions, expense actions, selection mode). That layout makes the header hard to maintain and can encourage unnecessary re-renders.
Goal
Split responsibility into focused hooks and components so the header stays thin and action logic lives next to the right Onyx/data access:
useReportPrimaryAction — primary action derivation; getReportPrimaryAction returns a plain value (no animation coupling)
useExpenseActions — secondary expense actions (hold, unhold, etc.); isReportInSearch passed in instead of hardcoded
useTransactionThreadReport — loads the transaction thread report internally via useOnyx
ActionsBar — renders subcomponents directly (no ReactNode props that force parent re-renders)
MoneyReportHeaderHoldMenu — extracted with an early return so the heavy menu tree is skipped when unused
Remove dead code (e.g. unused selection/payment refs and duplicated callbacks)
Target: shrink MoneyReportHeader to a small shell (~300 lines) with behavior owned by the hooks above.
Summary: This is a well-scoped refactoring issue with an active implementation PR (Expensify/App#87361) that currently has merge conflicts and needs resolution before it can proceed.
Current State:
MoneyReportHeader.tsx is 2,093 lines on main — none of the proposed hooks have been extracted yet
changed the title [-]Refactor: extract MoneyReportHeader actions into hooks and components[/-][+][$250] Refactor: extract MoneyReportHeader actions into hooks and components[/+]on Apr 15, 2026
Please re-state the problem that we are trying to solve in this issue.
MoneyReportHeader.tsx has grown to 2189 lines on main, mixing 30+ useOnyx subscriptions, animation state, business logic callbacks, and JSX rendering in one function body. Any state change anywhere in the component re-evaluates the entire secondaryActionsImplementation record and primaryActionsImplementation map on every render.
What is the root cause of that problem?
Three concrete architectural problems, each independently causing unnecessary work:
1. getReportPrimaryAction is coupled to animation state (src/libs/ReportPrimaryActionUtils.ts:62-79, src/libs/ReportPrimaryActionUtils.ts:443-449). The GetReportPrimaryActionParams type includes isPaidAnimationRunning, isApprovedAnimationRunning, and isSubmittingAnimationRunning. A pure action-derivation utility has no business reading UI animation flags. The useMemo at src/components/MoneyReportHeader.tsx:955-991 re-runs on every animation tick, re-deriving the action from scratch each frame.
2. Transaction thread report lookup is split across parent and child. The transactionThreadReportID prop is computed by the parent (MoneyRequestReportView.tsx:135, ReportScreen.tsx:327) via getOneTransactionThreadReportID, then the header fetches the report from Onyx itself (MoneyReportHeader.tsx:232). The issue wants useTransactionThreadReport to own both steps internally, eliminating the prop.
3. Both primaryActionsImplementation and secondaryActionsImplementation are built as inline records (lines 1139-1294 and 1370-1772). They hold ~630 lines of JSX and callback definitions that rebuild on any render of the parent component, even renders unrelated to actions. ProcessMoneyReportHoldMenu at lines 2042-2062 is guarded by isHoldMenuVisible && requestType !== undefined in JSX, but JavaScript still evaluates all its prop expressions every render.
What changes do you think we should make in order to solve the problem?
src/libs/ReportPrimaryActionUtils.ts
Remove isPaidAnimationRunning, isApprovedAnimationRunning, isSubmittingAnimationRunning from GetReportPrimaryActionParams (lines 76-78) and delete the animation override block (lines 443-449). getReportPrimaryAction becomes a pure function of report/transaction/policy data.
This mirrors the existing usePaymentAnimations hook at src/hooks/usePaymentAnimations.ts - animation state stays in the hook layer. MoneyReportHeader drops the primaryAction useMemo (lines 955-991) entirely and calls useReportPrimaryAction instead.
This is identical to the pattern already used in src/pages/ReportDetailsPage.tsx:185 + src/components/MoneyRequestReportView/MoneyRequestReportView.tsx:135,163 - those callers derive transactionThreadReportID then immediately useOnyx the result. The hook owns both steps. Remove transactionThreadReportID from MoneyReportHeaderProps (line 190) since the header now derives it internally.
src/hooks/useExpenseActions.ts (new)
Extract confirmPayment (lines 615-700), confirmApproval (lines 715-741), markAsCash (lines 743-753), duplicateExpenseTransaction (lines 758-813), and the hold menu state (isHoldMenuVisible, paymentType, requestType) into a focused hook. Accept isReportInSearch as a param (currently hardcoded at line 610 from route.name). Pattern to follow: useSelectedTransactionsActions at src/hooks/useSelectedTransactionsActions.ts - same shape (hook accepts report/policy/session, returns callbacks + state).
src/components/MoneyReportHeaderActions/index.tsx (new - ActionsBar)
Extract the actions bar at lines 1959-2017. Accepts primaryAction, applicableSecondaryActions, selectedTransactionsOptions, and callbacks - no ReactNode props. The primaryActionsImplementation map (lines 1139-1294) moves inside this component so it only rebuilds when action-relevant state changes, not on every parent render.
The early return means React skips the component subtree entirely when unused, vs the current JSX guard (line 2042) which still evaluates all prop expressions every render.
src/components/MoneyReportHeader.tsx
After extractions: remove the 30+ variable declarations that move into hooks, the primaryActionsImplementation record, the secondaryActionsImplementation record, and the inline hold menu JSX. Target is ~300 lines of thin shell that wires hooks together and renders the layout.
What alternative solutions did you explore?
I looked at whether secondaryActionsImplementation could be memoized in place using a deep-equal selector pattern, but the record has 18 keys each with onSelected closures capturing different state slices - a useCallback per key approach still leaves the record construction in the component. Moving the whole block into useExpenseActions is cleaner and consistent with how useSelectedTransactionsActions already handles the bulk-edit equivalents.
Activity
MelvinBot commentedon Apr 15, 2026
Issue Analysis
Summary: This is a well-scoped refactoring issue with an active implementation PR (Expensify/App#87361) that currently has merge conflicts and needs resolution before it can proceed.
Current State:
MoneyReportHeader.tsxis 2,093 lines onmain— none of the proposed hooks have been extracted yetPR #87361 extraction plan details
The PR creates these new files:
Hooks (in
src/hooks/):useReportPrimaryAction.ts— primary action derivation (59 lines)useExpenseActions.ts— secondary expense action callbacks (556 lines)useExportActions.ts— export-related actions (268 lines)useHoldRejectActions.ts— hold/reject logic (120 lines)useLifecycleActions.tsx— lifecycle management (385 lines)useTransactionThreadReport.ts— fetches transaction thread viauseOnyx(40 lines)Components (in
src/components/MoneyReportHeaderActions/):index.tsx— actions bar entry point (90 lines)MoneyReportHeaderSecondaryActions.tsx— secondary actions UI (397 lines)MoneyReportHeaderSelectionDropdown.tsx— selection mode dropdown (546 lines)Also adds:
PaymentAnimationsContext.tsxto decouple animation state fromgetReportPrimaryActionRemoves: ~2,003 lines from
MoneyReportHeader.tsx, 14 lines fromReportPrimaryActionUtils.ts, dead code refsPossibly related open issues:
Recommended Next Step: Resolve the merge conflicts on PR #87361 branch (
perf/extract-money-report-header-actions) againstmainto unblock review.Next Steps: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.melvin-bot commentedon Apr 15, 2026
Current assignee @abzokhattab is eligible for the External assigner, not assigning anyone new.
[-]Refactor: extract MoneyReportHeader actions into hooks and components[/-][+][$250] Refactor: extract MoneyReportHeader actions into hooks and components[/+]melvin-bot commentedon Apr 15, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022044207170746363662
yuvrajangadsingh commentedon Apr 15, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
MoneyReportHeader.tsxhas grown to 2189 lines onmain, mixing 30+useOnyxsubscriptions, animation state, business logic callbacks, and JSX rendering in one function body. Any state change anywhere in the component re-evaluates the entiresecondaryActionsImplementationrecord andprimaryActionsImplementationmap on every render.What is the root cause of that problem?
Three concrete architectural problems, each independently causing unnecessary work:
1.
getReportPrimaryActionis coupled to animation state (src/libs/ReportPrimaryActionUtils.ts:62-79,src/libs/ReportPrimaryActionUtils.ts:443-449). TheGetReportPrimaryActionParamstype includesisPaidAnimationRunning,isApprovedAnimationRunning, andisSubmittingAnimationRunning. A pure action-derivation utility has no business reading UI animation flags. TheuseMemoatsrc/components/MoneyReportHeader.tsx:955-991re-runs on every animation tick, re-deriving the action from scratch each frame.2. Transaction thread report lookup is split across parent and child. The
transactionThreadReportIDprop is computed by the parent (MoneyRequestReportView.tsx:135,ReportScreen.tsx:327) viagetOneTransactionThreadReportID, then the header fetches the report from Onyx itself (MoneyReportHeader.tsx:232). The issue wantsuseTransactionThreadReportto own both steps internally, eliminating the prop.3. Both
primaryActionsImplementationandsecondaryActionsImplementationare built as inline records (lines 1139-1294 and 1370-1772). They hold ~630 lines of JSX and callback definitions that rebuild on any render of the parent component, even renders unrelated to actions.ProcessMoneyReportHoldMenuat lines 2042-2062 is guarded byisHoldMenuVisible && requestType !== undefinedin JSX, but JavaScript still evaluates all its prop expressions every render.What changes do you think we should make in order to solve the problem?
src/libs/ReportPrimaryActionUtils.tsRemove
isPaidAnimationRunning,isApprovedAnimationRunning,isSubmittingAnimationRunningfromGetReportPrimaryActionParams(lines 76-78) and delete the animation override block (lines 443-449).getReportPrimaryActionbecomes a pure function of report/transaction/policy data.src/hooks/useReportPrimaryAction.ts(new)This mirrors the existing
usePaymentAnimationshook atsrc/hooks/usePaymentAnimations.ts- animation state stays in the hook layer.MoneyReportHeaderdrops theprimaryActionuseMemo (lines 955-991) entirely and callsuseReportPrimaryActioninstead.src/hooks/useTransactionThreadReport.ts(new)This is identical to the pattern already used in
src/pages/ReportDetailsPage.tsx:185+src/components/MoneyRequestReportView/MoneyRequestReportView.tsx:135,163- those callers derivetransactionThreadReportIDthen immediatelyuseOnyxthe result. The hook owns both steps. RemovetransactionThreadReportIDfromMoneyReportHeaderProps(line 190) since the header now derives it internally.src/hooks/useExpenseActions.ts(new)Extract
confirmPayment(lines 615-700),confirmApproval(lines 715-741),markAsCash(lines 743-753),duplicateExpenseTransaction(lines 758-813), and the hold menu state (isHoldMenuVisible,paymentType,requestType) into a focused hook. AcceptisReportInSearchas a param (currently hardcoded at line 610 fromroute.name). Pattern to follow:useSelectedTransactionsActionsatsrc/hooks/useSelectedTransactionsActions.ts- same shape (hook accepts report/policy/session, returns callbacks + state).src/components/MoneyReportHeaderActions/index.tsx(new - ActionsBar)Extract the actions bar at lines 1959-2017. Accepts
primaryAction,applicableSecondaryActions,selectedTransactionsOptions, and callbacks - no ReactNode props. TheprimaryActionsImplementationmap (lines 1139-1294) moves inside this component so it only rebuilds when action-relevant state changes, not on every parent render.src/components/MoneyReportHeaderHoldMenu.tsx(new)The early return means React skips the component subtree entirely when unused, vs the current JSX guard (line 2042) which still evaluates all prop expressions every render.
src/components/MoneyReportHeader.tsxAfter extractions: remove the 30+ variable declarations that move into hooks, the
primaryActionsImplementationrecord, thesecondaryActionsImplementationrecord, and the inline hold menu JSX. Target is ~300 lines of thin shell that wires hooks together and renders the layout.What alternative solutions did you explore?
I looked at whether
secondaryActionsImplementationcould be memoized in place using a deep-equal selector pattern, but the record has 18 keys each withonSelectedclosures capturing different state slices - auseCallbackper key approach still leaves the record construction in the component. Moving the whole block intouseExpenseActionsis cleaner and consistent with howuseSelectedTransactionsActionsalready handles the bulk-edit equivalents.alexanderxfgl-bit commentedon Apr 15, 2026
I can help refactor the
MoneyReportHeadercomponent to improve maintainability and performance.Proposed Approach:
useReportPrimaryActionfor primary action derivationuseExpenseActionsfor secondary expense actionsuseTransactionThreadReportfor transaction thread loadingImplementation Plan:
The goal is to reduce the header to a small (~300 line) shell while maintaining all existing functionality and improving performance.
18 remaining items
melvin-bot commentedon Apr 28, 2026
@abzokhattab 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
rlinoz commentedon Apr 29, 2026
@TMisiukiewicz can you confirm whether we are done here?
TMisiukiewicz commentedon Apr 29, 2026
@rlinoz yes we are done ✅
melvin-bot commentedon Apr 29, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)melvin-bot commentedon Apr 29, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)melvin-bot commentedon Apr 29, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)melvin-bot commentedon Apr 30, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
mallenexpensify commentedon May 1, 2026
Payment Summary
Contributor+: @abzokhattab due $250 via NewDot
I think that's correct and, with it being a refactor, don't think we need a BZ checklist. Comment/reopen, if needed
quinthar commentedon May 12, 2026
Approved $250 to @abzokhattab