Skip to content

[Due for payment 2026-07-14][$250] Perf/decompose money request report preview #94603

Closed
2 of 2 issues completed

Description

@mountiny

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 — useReportPreviewCarousel and usePreviewMessageAnimation hooks; ReportPreviewHeader, TransactionReportCarousel, ReportPreviewTotal, and a gated renderless ReportPreviewHoldMenu; the shell becomes composition only.
  • Remove prop drilling via context — a MoneyRequestReportPreviewProvider owns 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

#94563

Issue OwnerCurrent Issue Owner: @mallenexpensify
Upwork Automation - Do Not Edit

Activity

  1. added
    ReviewingHas a PR in review
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 25, 2026
  2. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jun 25, 2026
  3. melvin-bot commented on Jun 25, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @abzokhattab (External)

  4. changed the title [-]Perf/decompose money request report preview[/-] [+][$250] Perf/decompose money request report preview[/+] on Jun 25, 2026
  5. melvin-bot commented on Jun 25, 2026

    @melvin-bot
  6. kitvasyl commented on Jun 25, 2026

    @kitvasyl

    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 per REPORT_PREVIEW action in ReportActionsList, 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 its FlashList and 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:

    1. Carousel scroll state (lines 378–399): currentIndex, currentVisibleItems, optimisticIndex, carouselKey, and footerWidth are plain useState variables. Scrolling or navigating the carousel flips one of these, which re-executes the entire component body including the carouselTransactions sort (line 356–369) and all animation useEffect calls (lines 326–354).

    2. Animation shared values (lines 201–211, 326–354): previewMessageOpacity, checkMarkScale, and thumbsUpScale are Reanimated shared values whose driving useEffect hooks fire inside the same render cycle as carousel changes, widening the blast radius.

    3. Hold-menu UI state (lines 184–195): isHoldMenuVisible, requestType, and paymentType are more useState variables. Opening or closing the hold menu re-renders the full component including the FlashList.

    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.tsx passes ~16 props down to MoneyRequestReportPreviewContent, which in turn drills many of them further to ReportPreviewActionButton and 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 — owns currentIndex, currentVisibleItems, optimisticIndex, carouselKey, footerWidth, the carouselTransactions sort, and the carousel reset useEffect. Returns stable callbacks for scroll navigation.
    • usePreviewMessageAnimation — owns previewMessageOpacity, checkMarkScale, thumbsUpScale shared values and their three driving useEffect hooks. Returns previewMessageStyle and 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 the FlashList + 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 mounts ProcessMoneyReportHoldMenu only when isHoldMenuVisible is true; reads only the hold-menu context slice.

    Step 3 — Add a context provider with separate slices

    Create MoneyRequestReportPreviewProvider (co-located in the MoneyRequestReportPreview/ 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:

    ReportPreviewReportDataContext      // iouReport, chatReport, policy, …
    ReportPreviewLoadingContext         // shouldShowPreviewLoading, shouldShowSkeleton, …
    ReportPreviewCarouselListContext    // carouselTransactions
    ReportPreviewCarouselScrollContext  // currentIndex, optimisticIndex, scroll callbacks
    ReportPreviewAnimationContext       // previewMessageStyle, checkMarkScale, thumbsUpScale
    ReportPreviewActionCallbacksContext // openReportFromPreview, handleHoldMenuOpen, …
    ReportPreviewRefsContext            // carouselRef, contextMenuAnchorRef
    ReportPreviewHoldMenuContext        // isHoldMenuVisible, requestType, paymentType
    

    The shell MoneyRequestReportPreviewContent becomes 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 of MoneyRequestReportPreview (the index.tsx wrapper 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 ReportPreviewHeader or ReportPreviewTotal (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.memo and stabilise all callback props with useCallback. 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.

  7. 43 remaining items

  8. cristipaval commented on Jul 9, 2026

    @cristipaval
    Contributor

    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: TransactionPreview and TransactionPreviewContent are 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.

  9. melvin-bot commented on Jul 9, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    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.

  10. changed the title [-][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[/+] on Jul 9, 2026
  11. melvin-bot commented on Jul 13, 2026

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@mallenexpensify)

    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/2070180975122419663/hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  12. melvin-bot commented on Jul 14, 2026

    @melvin-bot

    @mallenexpensify Eep! 4 days overdue now. Issues have feelings too...

  13. melvin-bot commented on Jul 16, 2026

    @melvin-bot

    @mallenexpensify 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

  14. mallenexpensify commented on Jul 16, 2026

    @mallenexpensify
    Contributor

    @abzokhattab from the C+ doc

    If there are posts on the PR or issue that reference a regression or deploy blocker, C+ posts on the issue and confirms regression (which will reduce pay by 50%) or provides reasoning why they shouldn’t be considered. If the C+ doesn’t update the issue, the contributor manager making the payment will assume any mention of a regression or deploy blockers reduces the issue amount.

    ⚠️ Looks like this issue was linked to a Deploy Blocker #95721

    @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

  15. abzokhattab commented on Jul 17, 2026

    @abzokhattab
    Contributor

    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

  16. mallenexpensify commented on Jul 17, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @abzokhattab due $250 via NewDot

  17. quinthar commented on Aug 19, 2026

    @quinthar
    Contributor

    Approved $250 to @abzokhattab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions