Skip to content

Decompose PureReportActionItem to isolate hooks per action type #87157

Closed
14 of 14 issues completed
Closed

Description

@cristipaval

Problem

PureReportActionItem is a 2,200+ line monolith with 100+ if/else if branches. Every render evaluates the full chain and runs all top-level hooks (useOnyx, useMemo) regardless of which action type is actually being displayed.

Proposed fix

Extract groups of related branches into focused child components (PolicyChangeLogContent, ApprovalFlowContent, PaymentContent, etc.), then move action-type-specific hooks into those children so they only run when needed.

Issue OwnerCurrent Issue Owner: @LukasMod

Sub-issues

Sub-issues

14 of 14 Issues completed
Loading 14 sub-issues

Activity

  1. self-assigned this
    on Apr 6, 2026
  2. LukasMod commented on Apr 7, 2026

    @LukasMod
    Contributor

    I'm trying to keep phases clean so it will be possible to prepare PRs commit by commit later.
    First I want to check how much we can get from low-risk changes in component structure only with this strategy.

    Done:

    • Phase 1: Add unit tests (c564c511c1e)
    • Phase 2: Extract 4 content renderers: SimpleMessageContent, PaymentContent, PolicyChangeLogContent, ApprovalFlowContent (62e0b39961f)
    • Phase 3 (ActionableWhisperContent): Extract 3 actionable whisper branches (fraud alert, join request, mention whisper) into a self-contained component with their own button logic (dd852e7f55d)
    • Phase 4 (ChatMessageContent): Extract the default chat message branch along with 3 useOnyx calls, 2 custom hooks, actionableItemButtons useMemo, moderation state, and 2 context provider useMemos (2a04dc707df)
    • Phase 5 (ModifiedExpenseContent + ReimbursementDeQueuedContent): Extract remaining content renderers (4c923d0f4f8 + 570e13e2f87)

    Current results:

    I stopped refactor to get some measurements. Metric itself and profiler results sadly stays the same. There is noise in results so no winner so far. For sure its getting more readable with each step (8 new components from PureReportActionItem).
    I noticed some consistency in Performance trace improvements when tested chat with ~90 items:

    • ReportActionItem: 240ms → 165ms (-31%, total time for all list items)
    • PureReportActionItem: 92ms → 66ms (-28%, total time for all list items)
    • -6 subscription per message (-12%)
    • -425 total onyx subscriptions

    In progress (low risk):

    • Phase 6: Push cardList into self-subscribing CardBrokenConnectionContent
    • Phase 7: Push taskReport into TaskPreview
    • Phase 8: Push linkedReport + iouReportOfLinkedReport into TripRoomPreview
  3. LukasMod commented on Apr 7, 2026

    @LukasMod
    Contributor

    I finished phases 6-8 and 3 more ideas:

    • Phase 9: Push userBillingGracePeriodEnds into ChatMessageContent Extract ChatTransactionPreview
    • Phase 10: Extract ReimbursementQueuedContent — remove bankAccountList + missingPaymentMethod from per-item path and move it down to specific branch
    • Phase 11: Conditional useOnyx in ReportActionItemMessage for IOU branch

    With phase 11 I managed to get some consistent improvement in span metric.
    PureReportActionItem was reduced from ~2250 lines to ~1400.
    Each comment message creates 14 less useOnyx subscriptions.

    Phase Avg Span Span Delta Subs/msg Sub Delta
    Baseline 838ms -- +52 --
    Phase 5 824ms (noise) +46 -6 (-12%)
    Phase 10 843ms (noise) +41 -11 (-21%)
    Phase 11 773ms -65ms (-8%) +38 -14 (-27%)

    I will split main PR to small ones

  4. added
    Reviewing
    Weekly
    and removed
    Daily
    on Apr 8, 2026
  5. LukasMod commented on Apr 8, 2026

    @LukasMod
    Contributor

    Update:
    Phase 1 (unit tests): #87347 - ready for review
    Phase 2 (basic split): I will prepare four small PRs, one for each new grouping component. I’ll keep this based on the unit test branch for now and mark it as a draft until the tests are merged.

    1. refactor: PureReportActionItem, add SimpleMessageContent #87359
    2. refactor: PureReportActionItem, add PaymentContent #87399
    3. refactor: PureReportActionItem, add ApprovalFlowContent #87462
    4. refactor: PureReportActionItem, add PolicyChangeLogContent #87492

    Phase 3 (Whisper components): #87507 (-1 useOnyx from moving down useReportIsArchived)

  6. cristipaval commented on Apr 8, 2026

    @cristipaval
    ContributorAuthor

    Thanks @LukasMod! Love the investigation and the detailed updates!

  7. LukasMod commented on Apr 10, 2026

    @LukasMod
    Contributor

    I prepared another draft PR with the Phase 3 changes (the list above has been updated). It would be great if we could proceed with this one: #87347, as it provides a safe base for all changes (Phase 1 unit tests). I’m trying to keep the remaining changes separate from each other (at least so far)

  8. cristipaval commented on Apr 10, 2026

    @cristipaval
    ContributorAuthor

    Thanks @LukasMod. #87347 has been merged

  9. added
    Weekly
    and removed
    Weekly
    on Apr 13, 2026
  10. 41 remaining items

  11. LukasMod commented on Apr 24, 2026

    @LukasMod
    Contributor

    Phase 10 ready to review, Phase 11 almost ready (need to do some manual smoke tests and videos)

  12. LukasMod commented on Apr 27, 2026

    @LukasMod
    Contributor

    Last one from original plan #88601 is ready for review. Tomorrow I plan to check if there is something more to move around after all this effort so far

  13. LukasMod commented on Apr 28, 2026

    @LukasMod
    Contributor

    Follow-up decompositions of PureReportActionItem to push subscriptions down into leaves, which removes 6 onyx subs from regular ADD COMMENT report action (22 -> 16).

    1. reportMetadata → ApprovalFlowContent: useOnyx(REPORT_METADATA_<reportID>) only runs for SUBMITTED / APPROVED / FORWARDED actions.
    2. personalPolicyID → MentionWhisperContent: useOnyx(PERSONAL_POLICY_ID) only runs when a mention whisper is rendered.
    3. parentReport → ReimbursementQueuedContent + ReportActionItemContentCreated: useOnyx(REPORT_<parentReportID>) only runs in those branches.
    4. childReport → 4 explain-path leaves: useOnyx(REPORT_<childReportID>) removed from PureReportActionItem and inlined into ModifiedExpenseContent, ApprovalFlowContent, MovedTransactionAction, UnreportedTransactionAction.
    5. policy → IssueCardMessageContainer: new tiny container holds the useOnyx(POLICY_<policyID>) call and derives isPolicyAdmin. Five other leaves (ApprovalFlowContent, PaymentContent, PolicyChangeLogContent, JoinRequestContent, MentionWhisperContent) self-sub policy instead of receiving it as a prop.
    6. WhisperBanner extracted: the "Only visible to …" banner and its computations (whisperedToPersonalDetails, displayNamesWithTooltips, isMultipleParticipant, isWhisperOnlyVisibleByUser, getWhisperDisplayNames, useMemoizedLazyExpensifyIcons(['Eye'])) live in WhisperBanner.tsx. Mounts only when isWhisper === true.
    7. SearchActionHeader extracted: replaces the renderSearchHeader inline function with a self-gating component. Inner SearchActionHeaderContent (which holds useOnyx(CONCIERGE_REPORT_ID) and getChatListItemReportName) only mounts when isOnSearch === true.

    Each mounted ReportActionItem for a plain ADDCOMMENT on inbox now drops the following Onyx subscriptions vs. before this work:

    Subscription Before After
    REPORT_METADATA_<reportID> every cell only ApprovalFlow rows
    PERSONAL_POLICY_ID every cell only MentionWhisper rows
    REPORT_<parentReportID> every cell only ReimbursementQueued / created-thread-parent rows
    REPORT_<childReportID> every cell only inside 4 specialty leaves
    POLICY_<policyID> every cell only inside 6 policy-consuming leaves
    CONCIERGE_REPORT_ID every cell only on search

    While #88600 and #88601 are in review, I will prepare new PRs based on that. I think I will split this round into 2-3 PRs to avoid such noise with too many sub-issues, also these are not so complex. Currently I hold all changes in single POC draft PR #89107

    Mean from 30 messages in heavy account (exfy-perf account, web): 453.0 ms -> 438.7 ms (−3.2%)
    With 4,4x CPU slowdown (mid-tier phone simulation): 2405.0 ms -> 2072.4 ms (-13.8%)
    For 87 mounted list items totalSubscriptions drop (for whole app, but only comments in chat): 6689 -> 5921

  14. cristipaval commented on Apr 29, 2026

    @cristipaval
    ContributorAuthor

    Nice work on this round, @LukasMod! The -13.8% under CPU throttling and ~770 fewer subscriptions are solid numbers.

    I created #89164 to track this next phase. Let's create subissues there for the phases of this new round.

  15. cristipaval commented on Apr 29, 2026

    @cristipaval
    ContributorAuthor

    I'll close this issue when the last in review PRs are merged and deployed.

  16. LukasMod commented on Apr 29, 2026

    @LukasMod
    Contributor

    Sure, I will update plan with current PRs for sub-issues there soon

  17. melvin-bot commented on May 4, 2026

    @melvin-bot

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

  18. LukasMod commented on May 5, 2026

    @LukasMod
    Contributor

    All merged, waiting for last few to deploy

  19. melvin-bot commented on May 8, 2026

    @melvin-bot

    @LukasMod Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

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

Metadata

Metadata

Labels

Daily

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions