Skip to content

[Home Page] Fix: Your spend section does not update after updating expense offline V2 - Greyed out#96966

Open
adamgrzybowski wants to merge 1 commit into
Expensify:mainfrom
software-mansion-labs:@adamgrzybowski/fix-offline-your-spend-v2
Open

[Home Page] Fix: Your spend section does not update after updating expense offline V2 - Greyed out#96966
adamgrzybowski wants to merge 1 commit into
Expensify:mainfrom
software-mansion-labs:@adamgrzybowski/fix-offline-your-spend-v2

Conversation

@adamgrzybowski

@adamgrzybowski adamgrzybowski commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

  • Home "Your spend" totals come from server search snapshots that can't refresh offline, so they stayed stale after offline actions.
  • We now grey out only the total a pending offline change would move, signalling it may be out of date until the next online refresh.

This PR is created as a replacement for a more complicated solution implemented here #93081

Fixed Issues

$ #91370
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  1. Sign in with an account that owns a paid workspace and open the Home page so the "Your spend" section shows an "Awaiting approval" and a "Repaid" total.
  2. Go offline, then approve an outstanding report and pay another one; verify the "Awaiting approval" and "Repaid" totals grey out while the queued actions are pending.
  3. Go back online and verify both totals un-grey and refresh to their updated values, with no errors in the JS console.
  • 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 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 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)
  • 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)
  • 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.
  • 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
Screen.Recording.2026-07-24.at.15.41.22.mov

@adamgrzybowski adamgrzybowski changed the title Home - Your spend section does not update after updating expense offline [Home Page] Fix: Your spend section does not update after updating expense offline V2 - Greyed out Jul 24, 2026
@adamgrzybowski
adamgrzybowski marked this pull request as ready for review July 24, 2026 13:48
@adamgrzybowski
adamgrzybowski requested review from a team as code owners July 24, 2026 13:48
@melvin-bot
melvin-bot Bot requested review from ZhenjaHorbach and heyjennahay and removed request for a team July 24, 2026 13:48
@melvin-bot

melvin-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
...rc/pages/home/YourSpendSection/SpendSummaryRow.tsx 90.24% <100.00%> (ø)
src/pages/home/YourSpendSection/index.tsx 96.87% <100.00%> (ø)
...rc/pages/home/YourSpendSection/useYourSpendData.ts 97.29% <95.34%> (ø)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e38e04291

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

WRITE_COMMANDS.APPROVE_MONEY_REQUEST,
WRITE_COMMANDS.UNAPPROVE_EXPENSE_REPORT,
]);
const YOUR_SPEND_PAYMENT_COMMANDS = new Set<string>([WRITE_COMMANDS.PAY_MONEY_REQUEST, WRITE_COMMANDS.PAY_MONEY_REQUEST_WITH_WALLET, WRITE_COMMANDS.CANCEL_PAYMENT]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include MarkReportPaymentReceived in paid staleness

When the submitter uses the Received payment secondary action while offline, markReportPaymentReceived queues WRITE_COMMANDS.MARK_REPORT_PAYMENT_RECEIVED with reportID and optimistically moves the report to REIMBURSED, so it enters the status:paid query. This set filters that request out, and the projection only treats pendingFields.total as an amount change, so isPaymentStale stays false and the Repaid row shows an ungreyed stale snapshot until reconnect. Add MARK_REPORT_PAYMENT_RECEIVED to the payment bucket.

Useful? React with 👍 / 👎.

// refresh the snapshots, so we grey only the affected total to signal it may
// be stale rather than showing a value we know might be wrong.
const [reportsProjection] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {
selector: (reports) => projectYourSpendReports(reports, paidGroupPolicyIDs, accountID),

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.

❌ PERF-11 (docs)

This useOnyx selector on the REPORT collection returns projectYourSpendReports(...), whose statusByID field is a Record<string, number> that grows with the number of the user's paid-group reports. Onyx runs deepEqual on this output on every REPORT collection change (a very hot key), and the result is an intermediate structure that getYourSpendPendingBuckets only reduces further. On a high-traffic account this is an expensive deepEqual with no re-render savings — exactly the anti-pattern this rule warns about.

Mirror the sibling outstandingReportsSignature selector above, which reduces to a compact primitive. Compute the final booleans in the selector (or a compact string signature) rather than returning a growing statusByID map, e.g.:

const [reportsProjection] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {
    // return a small, stable signature/booleans instead of a per-report Record
    selector: (reports) => projectYourSpendReportsSignature(reports, paidGroupPolicyIDs, accountID),
});

Reviewed at: 4e38e04 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

});
const [queuedSpendRequests] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS, {
selector: (requests) =>
(requests ?? []).filter((request) => !!request?.command && (YOUR_SPEND_APPROVAL_COMMANDS.has(request.command) || YOUR_SPEND_PAYMENT_COMMANDS.has(request.command))),

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.

❌ PERF-11 (docs)

This selector on PERSISTED_REQUESTS returns a filtered array of full AnyRequest objects. Each request carries large nested payloads (optimisticData, successData, failureData, finallyData, etc.), so Onyx's deepEqual on this array runs a deep comparison over every field of every matching request on every queue mutation. This is the "filters/maps a collection into an array — deepEqual on every item" case the rule flags.

Project each request down to only the fields consumed downstream (command and the report ID) so the compared output is small:

const [queuedSpendRequests] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS, {
    selector: (requests) =>
        (requests ?? [])
            .filter((r) => !!r?.command && (YOUR_SPEND_APPROVAL_COMMANDS.has(r.command) || YOUR_SPEND_PAYMENT_COMMANDS.has(r.command)))
            .map((r) => ({command: r.command, reportID: r.data?.reportID ?? r.data?.iouReportID})),
});

(and adjust getYourSpendPendingBuckets to read the projected shape).


Reviewed at: 4e38e04 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

// title width across stacked rows, mirroring `ForYouSkeleton`.
skeletonRowIndex: number;
// Greys the total when a queued offline change may have made it stale.
isStale?: boolean;

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.

❌ CONSISTENCY-10 (docs)

The new isStale prop on SpendSummaryRowProps is documented with a // line comment. Per STYLE.md, component props must be documented with a /** ... */ block comment above the member, not a // comment.

    /** Greys the total when a queued offline change may have made it stale. */
    isStale?: boolean;

Reviewed at: 4e38e04 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
Built from App PR #96966.

Android 🤖 iOS 🍎
⏩ SKIPPED ⏩ ⏩ SKIPPED ⏩
The build for Android was skipped The build for iOS was skipped
Web 🕸️
https://96966.pr-testing.expensify.com
Web

👀 View the workflow run that generated this build 👀

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.

1 participant