Skip to content

perf: mark the revealed Inbox report read after the tap paints - #106843

Merged
JS00001 merged 4 commits into
Expensify:mainfrom
callstack-internal:perf/inbox-defer-mark-as-read
Nov 17, 2026
Merged

JS00001 merged 4 commits into
Expensify:mainfrom
callstack-internal:perf/inbox-defer-mark-as-read

Conversation

@BartekObudzinski

@BartekObudzinski BartekObudzinski commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

The Inbox tab is preloaded in the background, and useMarkAsRead holds the mark-as-read of the open report until the tab is shown. On the tap that shows it, the report is marked read inside the same commit. That write recomputes the derived report attributes and sorted actions and re-sorts the LHN, all before the sidebar finishes its first layout, which is where ManualNavigateToInboxTab ends. With window focus it even runs twice, once from the initial pass and once from the report-change pass.

This PR keeps the read but holds it until the main thread is idle (Scheduler.scheduleWhenIdle, the existing idle helper in src/libs/Scheduler) when the tap on the Inbox tab is what reveals the report. All of it lives in a new hook, useMarkReadAfterReveal. useMarkAsRead only routes its two reveal reads through it and cancels a held read from its other read paths. Every other read is unchanged, including the reveal of a wide submit pre-mount. To keep the outcome the same as an immediate read:

  • the held read is stamped with the reveal time (new optional readTime param on readNewestAction), so a message that arrives while it waits stays unread
  • it is skipped when the report's lastReadTime changed since the reveal (a comment, an expense, "Mark as read" from the context menu, or a "Mark as unread" synced from another tab)
  • a "Mark as unread" made before it runs cancels it
  • leaving or switching the report before it runs marks it read right away, except on sign-out, when nothing is read
  • both passes that react to the reveal share one held read, which also removes the duplicate read main sends today

Why it matters: in production, preloaded Inbox taps that open a report get slower the longer the user was away (Windows wide p50 179ms under 1 minute, 239ms after more than 1 hour; Mac 101ms to 151ms). The longer the user is away, the more likely the last report has unread messages, so the tap pays for marking it read. Taps where the report is already read never reach this path, so they are unchanged.

Local A/B of ManualNavigateToInboxTab (web, production build, 2x CPU throttling, window focus emulated, last report unread, 8 interleaved taps per arm):

mean median vs main
main 295ms 291ms
this PR (Scheduler.scheduleWhenIdle) 239ms 240ms -56ms (-18.9%, z 2.78)
same hold with raw requestIdleCallback, for comparison 236ms 242ms -59ms (-20.0%, z 2.83)

In the profiles, the readNewestAction, OnyxDerived recompute and LHN re-filter time between the tap and the span end drops to zero.

The only visible difference: the open report's LHN row can stay bold for about 100 to 150ms after the tap before it switches to read.

Fixed Issues

$ #106860
PROPOSAL: N/A

Tests

  1. Use a wide screen (desktop web, or a tablet in landscape)
  2. Open a chat and mark its latest message as unread (right click > Mark as unread)
  3. Wait a couple of seconds so the request is sent, then go to Home and reload the page
  4. Tap Inbox
  5. Verify the chat opens and is marked read within a moment (its LHN row is no longer bold and the Unread count drops)
  6. Verify the "New" line still shows above the message you marked unread
  7. Mark a message in that chat as unread again
  8. Verify the chat stays unread
  9. Repeat steps 2 to 4, then open another chat right after the tap
  10. Without opening the first chat again, verify its LHN row is no longer bold
  11. From an already opened Inbox, open an unread chat from the LHN and verify it is marked read as before
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline
  2. Do Tests steps 1 to 4
  3. Verify the chat shows as read
  4. Go online and verify it stays read after the queued request is sent

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 verified any copy / text that was added to the app 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 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 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 the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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

Chrome, production build, scripted against the local server with window focus emulated. Final read state taken from Onyx storage, 2 runs per build, same result on main and this PR:

Scenario main this PR
Tap Inbox with an unread last chat read, "New" line kept read, "New" line kept
Mark unread right after the tap stays unread stays unread
Open another chat right after the tap first chat read first chat read
Open an unread chat in an already open Inbox read read

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

This comment has been minimized.

@JS00001
JS00001 marked this pull request as ready for review November 13, 2026 14:48
@JS00001
JS00001 requested review from a team as code owners November 13, 2026 14:48
@melvin-bot
melvin-bot Bot requested review from DylanDylann and removed request for a team November 13, 2026 14:48
@melvin-bot

melvin-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

@DylanDylann 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 heyjennahay and removed request for a team November 13, 2026 14:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T15:10:57.259420Z 941e8ce Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@BartekObudzinski

Copy link
Copy Markdown
Contributor Author

@MelvinBot test

@MelvinBot

MelvinBot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Web test steps verification results: ⚠️ partial

Verified a wide desktop viewport on dev NewDot web. Testing was blocked by unsupported right-click, prohibited reload, and unavailable offline/online and console inspection capabilities; these are verification blockers, not confirmed app defects.

Wide desktop Inbox showing Concierge chat history and its welcome message.

Step Status
1. Use a wide desktop viewportConfirmed 1440×1000 viewport.
Wide desktop Inbox showing Concierge chat history and its welcome message.
✅
2. Mark latest chat message unreadChat opened, but right-click returned UNSUPPORTED_OPERATION.
❌
3. Wait, go Home, reloadUnread prerequisite blocked; session rules prohibit reload.
❌
4. Tap InboxInbox opened during setup, but not after the required sequence.
❌
5. Chat promptly becomes readNot verified: unread/reload sequence blocked.
❌
6. New divider remains visibleNot verified: message could not be marked unread.
❌
7. Mark message unread againBlocked by unsupported right-click.
❌
8. Chat stays unreadUnread state could not be established.
❌
9. Repeat reveal, immediately switch chatsBlocked by unsupported right-click and prohibited reload.
❌
10. First chat becomes readPreceding sequence could not be executed.
❌
11. Open an unread chat from InboxNo unread-chat fixture was established.
❌
12. No JS console errorsNot verified: console inspection unavailable.
❌
13. Go offlineNetwork offline control unavailable.
❌
14. Repeat reveal sequence offlineBlocked by unavailable offline control, unsupported right-click, and prohibited reload.
❌
15. Chat shows read offlineOffline scenario could not be established.
❌
16. Reconnect; chat stays readOffline/online transitions and queued-request behavior could not be verified.
❌

view run · view recording

@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: 941e8ce7c3

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

Comment thread src/hooks/useMarkReadAfterReveal.ts Resolved
Comment thread src/hooks/useMarkReadAfterReveal.ts Resolved
Comment thread src/hooks/useMarkReadAfterReveal.ts Resolved
heyjennahay
heyjennahay previously approved these changes Nov 16, 2026

@heyjennahay heyjennahay 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.

Product change 👍

@DylanDylann

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
  • 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 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 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 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)
  • 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.
  • 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

Screen.Recording.2026-11-17.at.15.19.35.mov

@DylanDylann

Copy link
Copy Markdown
Contributor

@BartekObudzinski All good. But I noticed a bug on staging that can block the test step

  1. Mark as unread
  2. Open another chat
  3. Back to the chat in step 1
  4. The unread indicator still appears
Screen.Recording.2026-11-17.at.15.22.09.mov

@melvin-bot
melvin-bot Bot requested a review from JS00001 November 17, 2026 08:25
@DylanDylann

Copy link
Copy Markdown
Contributor

@BartekObudzinski Actually, I’m not sure this is a bug. Since it’s not related to our change, please update step 10 to avoid it.

  1. Verify the first chat is marked read

@BartekObudzinski

Copy link
Copy Markdown
Contributor Author

Updated step 10 so it checks the LHN row without going back into the chat. Thanks!

@JS00001
JS00001 merged commit 1c51c1c into Expensify:main Nov 17, 2026
39 of 43 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

Copy link
Copy Markdown
Contributor

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/JS00001 in version: 9.5.41-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed — this PR improves performance by briefly deferring automatic read-state updates without changing the user workflow or making existing article guidance incorrect.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/marcaaron in version: 9.5.41-2 🚀

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

Bundle Size Analysis (Sentry):

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.

6 participants