Repository navigation
Description
Problem
MoneyRequestReportPreviewContent (~800 lines, ~55 hook calls) is a single component that bundles five unrelated concerns in one render body — loading-state derivation, the preview-message animation, the header (name / status / expense count), the transaction carousel, and the hold menu. It's mounted once per REPORT_PREVIEW action inside the chat's ReportActionsList, so many instances are live at the same time.
Because everything shares one render and derived state is drilled down through deep prop chains (the action-button + total row alone relayed ~16 props), any state change has a wide blast radius: a single carousel scroll tick or a pay/approve animation frame re-renders the entire card — including the FlashList and every sibling — not just the part that actually changed.
Solution
Decompose MoneyRequestReportPreviewContent into focused, single-responsibility pieces and remove the prop drilling:
- Extract by concern —
useReportPreviewCarouselandusePreviewMessageAnimationhooks;ReportPreviewHeader,TransactionReportCarousel,ReportPreviewTotal, and a gated renderlessReportPreviewHoldMenu; the shell becomes composition only. - Remove prop drilling via context — a
MoneyRequestReportPreviewProviderowns all the derivations once and exposes them as separate context slices, one per concern: the report data, the loading/UI state, the carousel list, the carousel scroll state, the animation state, the action callbacks, and the refs. Each component reads only the slice(s) it needs, so a change to one slice (e.g. a carousel scroll or a pay/approve animation) doesn't re-render the consumers of another.
PR
Issue Owner
Current Issue Owner: @mallenexpensifyUpwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022070180975122419663
- Upwork Job ID: 2070180975122419663
- Last Price Increase: 2026-06-25
Activity
melvin-bot commentedon Jun 25, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @abzokhattab (
External)[-]Perf/decompose money request report preview[/-][+][$250] Perf/decompose money request report preview[/+]melvin-bot commentedon Jun 25, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022070180975122419663
kitvasyl commentedon Jun 25, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
MoneyRequestReportPreviewContent(src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx) is an ~800-line component with ~55 hook calls that mixes five unrelated concerns in a single render body. Because the component is mounted once perREPORT_PREVIEWaction inReportActionsList, many instances are live simultaneously. Any isolated state change — a carousel scroll tick, a pay/approve animation frame, or a hold-menu toggle — re-renders the entire card including itsFlashListand all siblings, not just the part that changed.What is the root cause of that problem?
Three independent state domains live in the same render scope with no isolation boundary:
Carousel scroll state (lines 378–399):
currentIndex,currentVisibleItems,optimisticIndex,carouselKey, andfooterWidthare plainuseStatevariables. Scrolling or navigating the carousel flips one of these, which re-executes the entire component body including thecarouselTransactionssort (line 356–369) and all animationuseEffectcalls (lines 326–354).Animation shared values (lines 201–211, 326–354):
previewMessageOpacity,checkMarkScale, andthumbsUpScaleare Reanimated shared values whose drivinguseEffecthooks fire inside the same render cycle as carousel changes, widening the blast radius.Hold-menu UI state (lines 184–195):
isHoldMenuVisible,requestType, andpaymentTypeare moreuseStatevariables. Opening or closing the hold menu re-renders the full component including theFlashList.Because all state is co-located in the top-level component, React cannot isolate re-renders to sub-trees; every update to any concern forces a full reconciliation of ~800 lines and every child.
Additionally, the parent
index.tsxpasses ~16 props down toMoneyRequestReportPreviewContent, which in turn drills many of them further toReportPreviewActionButtonand the total row, so prop identity churn also triggers unnecessary child reconciliations.What changes do you think we should make in order to solve the problem?
Step 1 — Extract custom hooks
useReportPreviewCarousel— ownscurrentIndex,currentVisibleItems,optimisticIndex,carouselKey,footerWidth, thecarouselTransactionssort, and the carousel resetuseEffect. Returns stable callbacks for scroll navigation.usePreviewMessageAnimation— ownspreviewMessageOpacity,checkMarkScale,thumbsUpScaleshared values and their three drivinguseEffecthooks. ReturnspreviewMessageStyleand the animated scale values.Step 2 — Extract focused sub-components
ReportPreviewHeader— renders the name / status badge / expense count row; reads only report-data context slice.TransactionReportCarousel— renders theFlashList+ arrow buttons; reads only the carousel-state context slice. With isolation here, a scroll tick re-renders only this subtree.ReportPreviewTotal— renders the amount row and action button; reads only the action-callbacks and animation-state slices.ReportPreviewHoldMenu— renderless gate that mountsProcessMoneyReportHoldMenuonly whenisHoldMenuVisibleistrue; reads only the hold-menu context slice.Step 3 — Add a context provider with separate slices
Create
MoneyRequestReportPreviewProvider(co-located in theMoneyRequestReportPreview/directory). The provider derives all values once and exposes them through separate context objects (one per concern) so React's bail-out logic can skip consumers whose slice did not change:The shell
MoneyRequestReportPreviewContentbecomes composition-only: it wraps children in the provider and renders the four focused sub-components in order.Why this is the smallest safe fix: The change is purely internal to the
MoneyRequestReportPreview/directory. The public API ofMoneyRequestReportPreview(theindex.tsxwrapper and its props) is unchanged. No Onyx keys, no navigation logic, no i18n strings are touched.Manual verification: After the change, triggering a carousel scroll in a report with multiple expenses should not re-render
ReportPreviewHeaderorReportPreviewTotal(verifiable with React DevTools Profiler highlighting).What alternative solutions did you explore? (Optional)
A simpler approach would be to wrap the existing monolith in
React.memoand stabilise all callback props withuseCallback. This would reduce parent-triggered re-renders but would not isolate internal state domains from each other — a carousel scroll would still re-run every hook in the 800-line component. The context-slice decomposition described above is the minimal change that actually isolates each concern's re-render to its own sub-tree.43 remaining items
cristipaval commentedon Jul 9, 2026
Nice audit, thanks for digging into this, @OlimpiaZurek. The findings make sense to me.
I made a separate issue to track these subscription cleanups: #95706. I kept it as one issue with a checklist, since you plan a single follow-up PR and they are all the same kind of fix.
One thing to keep in mind:
TransactionPreviewandTransactionPreviewContentare used in other places too, not only in the carousel. So when you change their subscriptions, please also test the other spots where they render (transaction threads, Search). The Provider change is safe because it is specific to this subtree.Go ahead with the follow-up PR when ready.
melvin-bot commentedon Jul 9, 2026
If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.
If a regression has occurred and you are the assigned CM follow the instructions here.
If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.
[-][Due for payment 2026-07-14] [Due for payment 2026-07-08][$250] Perf/decompose money request report preview[/-][+][Due for payment 2026-07-14][$250] Perf/decompose money request report preview[/+]melvin-bot commentedon Jul 13, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
melvin-bot commentedon Jul 14, 2026
@mallenexpensify Eep! 4 days overdue now. Issues have feelings too...
melvin-bot commentedon Jul 16, 2026
@mallenexpensify 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
mallenexpensify commentedon Jul 16, 2026
@abzokhattab from the C+ doc
@abzokhattab plz complete the BZ checklist and tag me in a post once you have. Thx. Also.. let me know if this ISN'T due payment now, thx
abzokhattab commentedon Jul 17, 2026
The deployment blocker is unrelated.. it was fixed by reverting another pr here #95715
Also no checklist is needed for this as its a performance improvement
mallenexpensify commentedon Jul 17, 2026
Payment Summary
Contributor+: @abzokhattab due $250 via NewDot
quinthar commentedon Aug 19, 2026
Approved $250 to @abzokhattab