Skip to content

perf: feed stable report projection to transaction list to avoid read-state re-renders#92485

Merged
mountiny merged 3 commits into
Expensify:mainfrom
callstack-internal:perf/stable-report-transaction-list
Jun 3, 2026
Merged

perf: feed stable report projection to transaction list to avoid read-state re-renders#92485
mountiny merged 3 commits into
Expensify:mainfrom
callstack-internal:perf/stable-report-transaction-list

Conversation

@TMisiukiewicz

@TMisiukiewicz TMisiukiewicz commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

getStableReportSelector/reportStable already exist in MoneyRequestReportActionsList to produce a stable projection of the report object with read-state heartbeat fields (lastReadTime, lastVisibleActionCreated, lastMessageText, etc.) omitted. However, the full report — which re-renders on every chat heartbeat update — was still being passed down to MoneyRequestReportTransactionList. This meant every last* field mutation (e.g. marking a report as read, receiving a message) re-rendered the entire transaction-list subtree even though nothing inside it reads those fields.

This PR feeds reportStable (typed as StableReport) to MoneyRequestReportTransactionList instead. StableReport is structurally assignable to Report (the omitted fields are all optional), so all downstream consumers — row components, utility calls — need no changes. The !!reportStable guard preserves the existing conditional render. The net effect is that read-state churn no longer triggers re-renders of the transaction list. Behavior is identical to production; only the re-render trigger surface shrinks.

export type {StableReport} is added to src/selectors/Report.ts so the type is importable from the selector module.

Fixed Issues

$ #92491
PROPOSAL:

Tests

  1. Go to Spend tab -> Reports
  2. Open Report with multiple transactions (list must be scrollable)
  3. Scroll transactions a bit
  4. Press "Latest messages" once it appeared
  5. Verify you are scrolled to the bottom of the list
  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native

Android: mWeb Chrome

iOS: Native

iOS: mWeb Safari

MacOS: Chrome / Safari

@TMisiukiewicz TMisiukiewicz marked this pull request as ready for review June 3, 2026 09:32
@TMisiukiewicz TMisiukiewicz requested review from a team as code owners June 3, 2026 09:32
@melvin-bot melvin-bot Bot requested review from a team, heyjennahay and huult and removed request for a team June 3, 2026 09:32
@melvin-bot

melvin-bot Bot commented Jun 3, 2026

Copy link
Copy Markdown

@huult 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]

@melvin-bot melvin-bot Bot requested review from FitseTLT and rlinoz and removed request for a team June 3, 2026 09:32
@melvin-bot

melvin-bot Bot commented Jun 3, 2026

Copy link
Copy Markdown

@FitseTLT @rlinoz One of you needs to 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]

@huult

huult commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Do we need another C+ on this PR?

@aimane-chnaif

Copy link
Copy Markdown
Contributor

I'll be reviewing as part of #91422

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🚧 @mountiny has triggered a test Expensify/App build. You can view the workflow run here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces unnecessary re-renders in the money request report view by passing a stable, read-heartbeat-free projection of the Report object into the transaction list subtree, preventing chat read-state churn (e.g. lastReadTime, lastMessageText) from re-rendering the transaction list.

Changes:

  • Exported the StableReport type from src/selectors/Report.ts so it can be consumed externally.
  • Updated MoneyRequestReportTransactionList to accept a StableReport instead of the full Report.
  • Updated MoneyRequestReportActionsList to pass reportStable into MoneyRequestReportTransactionList (with an explicit truthy guard).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/selectors/Report.ts Exports StableReport type to support typed consumption of the stable report projection.
src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx Narrows report prop type to StableReport to avoid re-renders caused by read-state heartbeat fields.
src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx Passes reportStable into the transaction list (and keeps conditional rendering behavior via !!reportStable).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

This comment has been minimized.

@aimane-chnaif

Copy link
Copy Markdown
Contributor

job 4 failing

@TMisiukiewicz

Copy link
Copy Markdown
Contributor Author

looks like a timeout, not related to changes

@aimane-chnaif

aimane-chnaif commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
android.mov
Android: mWeb Chrome
iOS: HybridApp
ios.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ 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".

/>
{!!reportStable && (
<MoneyRequestReportTransactionList
report={reportStable}

@aimane-chnaif aimane-chnaif Jun 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot find out all occurrences in MoneyRequestReportTransactionList and its child components where report properties that don't exist in reportStable are referenced.

@MelvinBot

Copy link
Copy Markdown
Contributor

Review — looks correct and well-scoped ✅

The change swaps the full report for the reportStable projection into MoneyRequestReportTransactionList. The one real risk in this pattern is a silent regression: because StableReport is structurally assignable to Report (all 9 omitted last* fields are optional), TypeScript will not flag any downstream consumer that reads one of the omitted fields — it just receives undefined at runtime. I traced every reachable consumer and none read the omitted fields, so there's no behavioral change.

What I verified (the omitted fields are never read downstream)

Omitted by the projection: lastMessageText, lastVisibleActionCreated, lastReadTime, lastReadSequenceNumber, lastMentionedTime, lastVisibleActionLastModified, lastMessageHtml, lastActorAccountID, lastActionType.

  • Child components (MoneyRequestReportTransactionItem, SearchMoneyRequestReportEmptyState, MoneyRequestReportTotalSpend and their descendants TransactionItemRow/TotalCell/TransactionItemRowRBR): only read currency, policyID, type, statusNum, stateNum, total, submitted, approved, reportID, parentReportID, chatType, isWaitingOnBankAccount, pendingFields, ownerAccountID, managerID — all preserved. ChatBubbleCell does read lastReadTime/lastVisibleActionCreated/lastMentionedTime but fetches its own full report via useOnyx, not the report prop — so it's unaffected.
  • Util calls (getReportOfflinePendingActionAndErrors, getMoneyRequestSpendBreakdown, getBillableAndTaxTotal, canAddTransaction, isCurrentUserSubmitter, getTransactionSortValue, groupTransactionsByTag/Category, getVisibleTransactionViolations, transactionHasRBR): none touch an omitted field.
  • Navigation path handleOnPress → createTransactionThreadReport: passes report to Onyx.merge(..., iouReport) and buildTransactionThread. The merge is a partial merge so the omitted keys remain intact in Onyx (the projection drops the keys entirely rather than setting them to undefined), and buildTransactionThread reads only reportID/policyID. Safe.
  • managerID: 0 → undefined coercion in the selector: every managerID read in the canAddTransaction chain is an equality check against the current user's accountID, which is never 0, so 0 vs undefined produces the same result.

Worth confirming before merge (perf, not correctness)

The parent still self-subscribes to the full report at MoneyRequestReportActionsList.tsx:102, so it re-renders on every heartbeat regardless. The win depends entirely on MoneyRequestReportTransactionList being memo'd and all its other props (transactions, newTransactions, reportActions, the callbacks) staying referentially stable across a heartbeat. If any of those gets a new reference each render, the memo bails and this change is a no-op. A quick re-render profile (e.g. React DevTools highlight) before/after on a "mark as read" / incoming-message would confirm the projected win is actually realized.

Minor (non-blocking)

The new {!!reportStable && (...)} guard at MoneyRequestReportActionsList.tsx:718 is reached only after the if (!report) return null guard, and reportStable is undefined only when report.reportID is falsy — which shouldn't happen for a loaded report. So it's effectively always truthy here; harmless, just slightly redundant.


🤖 Generated with Claude Code

@MelvinBot

Copy link
Copy Markdown
Contributor

Answer: zero. Inside MoneyRequestReportTransactionList and every child component that receives the report prop, none of the 9 fields omitted by reportStable are referenced. The only place in the whole subtree that reads an omitted field is ChatBubbleCell — and it does not consume the report prop, so the projection swap doesn't affect it.

The omitted fields (getStableReportSelector / ExcludedFields): lastMessageText, lastVisibleActionCreated, lastReadTime, lastReadSequenceNumber, lastMentionedTime, lastVisibleActionLastModified, lastMessageHtml, lastActorAccountID, lastActionType.

The one occurrence — and why it's safe

ChatBubbleCell.tsx:21-22 reads lastReadTime, lastVisibleActionCreated, lastMentionedTime via isReportUnread(...). But the report it inspects is not the prop:

  • ChatBubbleCell only takes {transaction, containerStyles, isInSingleTransactionReport} — no report prop (line 24).
  • isReportUnread is called with transactionReport, which is parentReport/childReport from its own useOnyx(COLLECTION.REPORT...) subscriptions (lines 45-49, 54) — those return the full Report, never the StableReport projection.

So even though it reads omitted fields, it never touches the projection. No regression.

How I verified it's exhaustive (grep methodology)

Every component reachable from MoneyRequestReportTransactionList that receives report/iouReport lives in one of two directories:

  • src/components/MoneyRequestReportView/MoneyRequestReportTransactionItem, SearchMoneyRequestReportEmptyState, MoneyRequestReportTotalSpend, MoneyRequestReportGroupHeader
  • src/components/TransactionItemRow/TransactionItemRow (+ Wide/Narrow), DataCells/TotalCell, TransactionItemRowRBR, DataCells/ChatBubbleCell

Grepping both directories for all 9 field names returns only:

  • MoneyRequestReportTransactionList.tsx:117 — the new JSDoc comment (text, not a read)
  • MoneyRequestReportActionsList.tsx (lines 200, 318, 363, 375) — the parent, which deliberately keeps the full-report useOnyx subscription and is out of scope for this prop change
  • ChatBubbleCell.tsx:21-22 — the case above (own Onyx fetch)

No other file in the subtree references any omitted field.

One non-component exit point worth noting: handleOnPress passes report as iouReport into createTransactionThreadReport → it calls Onyx.merge(REPORT_key, iouReport) and buildTransactionThread(..., reportToUse). The merge is a partial merge so the omitted keys stay intact in Onyx (the projection drops the keys entirely rather than setting undefined), and buildTransactionThread reads only reportID/policyID. So that path is safe too — but it's a util, not a child component.


🤖 Generated with Claude Code

@mountiny mountiny merged commit 8bbe9c3 into Expensify:main Jun 3, 2026
41 of 43 checks passed
@OSBotify

OSBotify commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.3.99-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Help site review: no changes required.

This PR is a pure render-performance optimization with no user-facing behavior change, so nothing in App/docs/articles needs to be updated.

Why no docs changes are needed

The change feeds a stable report projection (reportStable / StableReport) into MoneyRequestReportTransactionList instead of the full report, so read-state field churn (lastReadTime, lastVisibleActionCreated, lastMessageText, etc.) no longer re-renders the transaction-list subtree.

  • src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx — passes reportStable and adds a !!reportStable render guard
  • src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx — prop type changed from Report to StableReport
  • src/selectors/Report.ts — exports the StableReport type

As stated in the PR description: "Behavior is identical to production; only the re-render trigger surface shrinks." Help articles document user-facing features, flows, and settings — none of which change here. There are no new buttons, tabs, labels, settings, or workflows to document.

No draft help site PR was created since no documentation updates apply.

@IuliiaHerets

Copy link
Copy Markdown

Hi @TMisiukiewicz. We have more than 30 expenses in the report, but the "Latest Messages" section does not appear on Web.
Does this PR apply only to the native apps?

Recording.805.mp4

cc @mountiny @heyjennahay @aimane-chnaif

@aimane-chnaif

Copy link
Copy Markdown
Contributor

Hi @TMisiukiewicz. We have more than 30 expenses in the report, but the "Latest Messages" section does not appear on Web. Does this PR apply only to the native apps?

Recording.805.mp4
cc @mountiny @heyjennahay @aimane-chnaif

Send any message in the report and try again

@OSBotify

OSBotify commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/lakchote in version: 9.3.99-9 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants