Skip to content

fix: reduce INP latency for receipt image interactions#96089

Open
nabi-ebrahimi wants to merge 1 commit into
Expensify:mainfrom
nabi-ebrahimi:fix/inp-receipt-image-interaction
Open

fix: reduce INP latency for receipt image interactions#96089
nabi-ebrahimi wants to merge 1 commit into
Expensify:mainfrom
nabi-ebrahimi:fix/inp-receipt-image-interaction

Conversation

@nabi-ebrahimi

@nabi-ebrahimi nabi-ebrahimi commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR improves the slow Receipt-Image INP interaction on web.

The Receipt-Image interaction happens when a user taps a receipt image in ReportActionItemImage to open the receipt preview modal. Previously, the press handler navigated to the receipt modal immediately, so heavier modal navigation work could begin before the browser had a chance to paint the receipt click feedback.

This PR moves the receipt modal navigation into a stable callback and, on web, defers the Navigation.navigate() call until after a double requestAnimationFrame() paint boundary. This gives the browser an opportunity to paint after the receipt click before starting the heavier modal navigation work. Native platforms keep the existing immediate navigation behavior.

Fixed Issues

$ #85595
PROPOSAL: #85595 (comment)

Tests

  1. First, build the app for the web.

  2. Open the app in Chrome with the Web Vitals extension enabled.

  3. Navigate to a report that has an expense with a receipt image.

  4. Refresh the page to reset the current page INP measurement.

  5. Click the receipt image to open the receipt preview modal.

  6. After the receipt modal opens, check the Web Vitals extension and record the INP value for the receipt image interaction.

  7. Do not measure the Back/Close interaction as part of this test. Record the receipt image result before clicking Back.

  8. Repeat the same steps before and after the change for comparison.

  9. Verify that the receipt preview modal opens successfully and the Receipt-Image interaction on the web shows improved INP (or no regression compared to the baseline). The Back/Close interaction should be excluded from this measurement.

  • Verify that no errors appear in the JS console

Offline tests

Same as Tests.

QA Steps

Same as Tests.

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • 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
Screen.Recording.2026-07-15.at.10.57.03.AM.mov
Android: mWeb Chrome
Screen_Recording_20260715_115043_Chrome.mp4
iOS: Native
Screen.Recording.2026-07-15.at.11.52.29.AM.mov
iOS: mWeb Safari
Screen.Recording.2026-07-15.at.11.56.41.AM.mov
MacOS: Chrome / Safari
Screencast.From.2026-07-15.10-05-10.mp4

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
...ponents/ReportActionItem/ReportActionItemImage.tsx 68.75% <20.00%> (-0.61%) ⬇️
... and 29 files with indirect coverage changes

@nabi-ebrahimi nabi-ebrahimi marked this pull request as ready for review July 15, 2026 07:43
@nabi-ebrahimi nabi-ebrahimi requested review from a team as code owners July 15, 2026 07:43
@melvin-bot melvin-bot Bot requested review from marufsharifi and trjExpensify and removed request for a team July 15, 2026 07:43
@melvin-bot

melvin-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

@marufsharifi 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 removed the request for review from a team July 15, 2026 07:43
// While the receipt is regenerating its stored URL is stale, so draw the live route from `routes.coordinates`
// (via `ConfirmedRoute`) instead of loading the now-404'd image.
const showMapAsImage = isMapDistanceRequest && (hasErrors || hasPendingDistanceReceiptRegeneration(transaction));
const navigateToReceipt = useCallback(() => {

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.

❌ CLEAN-REACT-PATTERNS-0 (docs)

React Compiler is enabled in this codebase and automatically memoizes closures based on their captured variables. This useCallback wrapping navigateToReceipt is redundant with the compiler's own memoization — the previous inline onPress arrow was already compiler-friendly. Manual memoization adds a dependency array that must be maintained and can interfere with the compiler's optimization model. (Note: this file could not be verified with the compliance check in this environment; disregard if it fails to compile.)

Remove the useCallback wrapper and let the compiler memoize the plain function:

const navigateToReceipt = () => {
    const navigate = () => {
        Navigation.navigate(
            ROUTES.TRANSACTION_RECEIPT.getRoute(
                transactionThreadReport?.reportID ?? contextReport?.reportID ?? reportProp?.reportID ?? getReportIDForExpense(transaction),
                transaction?.transactionID,
                readonly,
                mergeTransactionID,
            ),
        );
    };

    if (getPlatform() !== CONST.PLATFORM.WEB) {
        navigate();
        return;
    }

    requestAnimationFrame(() => {
        requestAnimationFrame(navigate);
    });
};

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

mergeTransactionID,
),
);
};

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-1 (docs)

The getPlatform() !== CONST.PLATFORM.WEB check embeds platform-specific behavior directly inside the component: web navigates after a double requestAnimationFrame, while all other platforms navigate immediately. Mixing platform branching into the component increases maintenance overhead and platform-specific bug risk. Separating platform concerns keeps the component logic uniform and easier to reason about.

Move the platform-specific scheduling into a dedicated platform-specific file (e.g. a deferNavigation.web.ts / deferNavigation.ts helper) so the component calls a single API without a getPlatform() branch:

// deferNavigation.ts (native/default)
function deferNavigation(navigate: () => void) {
    navigate();
}

// deferNavigation.web.ts
function deferNavigation(navigate: () => void) {
    requestAnimationFrame(() => {
        requestAnimationFrame(navigate);
    });
}

// in the component:
const navigateToReceipt = () => {
    deferNavigation(() => {
        Navigation.navigate(/* ... */);
    });
};

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

@marufsharifi

Copy link
Copy Markdown
Contributor

@nabi-ebrahimi, could you please address the AI comments?

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.

2 participants