Skip to content

Build mention name maps lazily for the composer and Concierge drafts - #106086

Merged
luacmartins merged 14 commits into
Expensify:mainfrom
callstack-internal:LukasMod/lazy-mention-name-maps
Nov 17, 2026
Merged

luacmartins merged 14 commits into
Expensify:mainfrom
callstack-internal:LukasMod/lazy-mention-name-maps

Conversation

@LukasMod

@LukasMod LukasMod commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

ComposerWithSuggestions and usePusherDraftPacing built the report-name and user-name maps over the whole COLLECTION.REPORT and PERSONAL_DETAILS_LIST collections, and the composer held both subscriptions. The maps are only needed when message HTML is converted back to markdown, so this PR builds them where the conversion happens and only for the IDs the HTML mentions.

  • Composer (ArrowUp to edit the last message): user names come from useMentionedAccountIDToNameMap, a selector that only maps the users mentioned in the last message. Report names are read once with Onyx.get in the key handler and mapped only for the mentioned rooms. That read carries a rulesdir/no-onyx-get-snapshot-key disable with a reason: Parser used to serve these names from a module-level Onyx.connect, the composer never renders inside a Search scope, so Onyx.get reads the same live reports.
  • Edit video cache (useDraftMessageVideoAttributeCache): runs inside the composer, so it now uses the same scoped hooks on the edited message, only while editing.
  • Concierge draft pacing (usePusherDraftPacing): keeps the personal details list in a ref instead of building the full name map on every render. When a draft event is applied, conciergeDraftState builds names only for the users mentioned in that draft.

@user and #room mentions are preserved in every path.

Measured on a heavy account (4,109 reports, 6,828 personal details), web dev build, 10 runs per side against main:

  • The composer's own render work per update drops 8 to 23x, for example 69.2 ms to 4.25 ms over 20 unrelated personal details writes, and 85 ms to 4.3 ms over 20 unrelated report writes.
  • The composer still re-renders as often as on main. ComposerProvider keeps full subscriptions through useEditMessage, which this PR does not touch, so each write still reaches the composer; it is just much cheaper now.

Fixed Issues

$ #104859
PROPOSAL:

Tests

  1. Open a workspace room or workspace chat (not a DM, where #room stays plain text) and send hi @someone@domain.com see #admins, using a real member and picking the room from the # suggestion list.
  2. Verify both mentions render as mentions in the sent message.
  3. With the composer empty, press ArrowUp.
  4. Verify the last message opens for editing with @someone@domain.com and #admins as markdown, not @Hidden, #Hidden or raw HTML.
  5. Save the edit without changes and verify both mentions still render and the message is not marked as edited.
  6. Hover the same message, open its menu (⋯), choose Edit comment, and verify the edit composer shows the same markdown.
  7. Send a message with *bold* _italic_ ~strike~ `code` https://example.com, a quote, a heading, a code block and a mention, press ArrowUp, and verify the draft matches what you sent.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline.
  2. In the chat from step 1, press ArrowUp with the composer empty, change one word and save.
  3. Verify the message shows as pending with both mentions intact.
  4. Go back online and verify the edit syncs and both mentions still render.

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.mov
Android: mWeb Chrome
android.web.mov
iOS: Native
ios.mov
iOS: mWeb Safari
ios.web.mov
MacOS: Chrome / Safari
web.1.mov
web.2.mov

@codecov

codecov Bot commented Nov 5, 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 Δ
src/hooks/useAccountIDToNameMap.ts 96.55% <100.00%> (+0.25%) ⬆️
src/hooks/useReportIDToNameMap.ts 97.36% <100.00%> (+0.39%) ⬆️
src/pages/inbox/conciergeDraftState.ts 89.24% <100.00%> (+0.03%) ⬆️
...inbox/report/useDraftMessageVideoAttributeCache.ts 100.00% <100.00%> (ø)
src/pages/inbox/usePusherDraftPacing.ts 85.63% <100.00%> (-0.03%) ⬇️
...rt/ReportActionCompose/ComposerWithSuggestions.tsx 81.65% <90.00%> (+1.08%) ⬆️
... and 5 files with indirect coverage changes

@LukasMod

LukasMod commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot deep review

@MelvinBot

Copy link
Copy Markdown
Contributor

Deep review

No actionable introduced bugs found at c2fd9aa540923de18dcd5a1490c55a8f8a26425b.

  • Scoped lookups: checked selector updates when the message changes, initial loading, unrelated writes, and Search snapshots. The new account selector and report selector scope mapping work and selected output, not the underlying collection subscriptions.
  • Editing: traced ArrowUp conversion and video-attribute caching. Checked the installed Onyx implementation: after initialization, the new read resolves cached data rather than awaiting network/storage, so a slow-read navigation race was not substantiated.
  • Concierge: traced paced draft publication through mention conversion. The store snapshot preserves the existing name fallback semantics; sequencing and cleanup are unchanged. Compared mention extraction against the installed parser's supported tag forms.

Automated verification: 6 targeted suites passed, 127 tests passed: composer imperative refs, Concierge draft state, both name-map hooks, edited-video cache, and Concierge draft context. No source changes made.

Non-blocking test improvements:

  1. Rerender a scoped hook from mention A → B → no mentions without an Onyx write; cover missing entries arriving later and being deleted.
  2. Exercise conflicting Search snapshot/live names and measure actual render counts, not only returned-reference equality.
  3. Give the added report-hook suite its own initialization/cleanup: the existing setup is scoped to an earlier describe, while the new suite is outside it.

Limits: no performance profiling was performed. Browser verification confirmed sending/rendering mentions, but could not verify editing, streaming, offline behavior, or console errors; those remain unverified, not failed product checks.


view run

@MelvinBot

MelvinBot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Web test steps verification results: ⚠️ partial

Verified sending and rendering genuine mentions; editing, streaming, offline, and console assertions remain blocked, so browser testing cannot confirm the editing fix. Deep code review found no actionable introduced bugs, and 6 targeted suites passed all 127 tests; remaining coverage suggestions and limitations are documented there.

Concierge request with no streamed response

Step Status
1. Open workspace chat and send real user and room mentionsSent autocomplete-selected user and room mentions.
✅
2. Both sent mentions renderSnapshot confirmed user and room links.
Sent user and room mentions in workspace chat
✅
3. Empty-composer ArrowUp opens last messageBlocked: supported browser tooling lacks keyboard-key injection.
⚠️
4. Edit markdown contains real names, not Hidden/raw HTMLBlocked: message editing could not be entered.
⚠️
5. Save unchanged preserves mentions without edited markerBlocked: message editing could not be entered.
⚠️
6. Context-menu Edit shows the same markdownBlocked: secondary-click/longpress operations were unsupported; hover did not expose editing controls.
⚠️
7. Mixed mentions and formatting round-trip via ArrowUpBlocked: ArrowUp injection unavailable.
⚠️
8. Concierge preserves user name during and after streamingNo response appeared during the observation window, including a 20-second wait; mention streaming remains unverified.
Concierge request with no streamed response
⚠️
9. Go offlineBlocked: network interception is outside supported browser capabilities.
⚠️
10. Offline ArrowUp edits a message containing both mentionsBlocked: offline control and ArrowUp injection unavailable.
⚠️
11. Offline edit preserves names and saves pendingBlocked: required offline editing state could not be established.
⚠️
12. No JavaScript console errorsUnverified: console access is outside supported browser capabilities.
⚠️

view run · view recording

@LukasMod
LukasMod force-pushed the LukasMod/lazy-mention-name-maps branch from c2fd9aa to 99e70f7 Compare November 9, 2026 07:54
@LukasMod
LukasMod force-pushed the LukasMod/lazy-mention-name-maps branch from 99e70f7 to fdebccb Compare November 9, 2026 11:30
@LukasMod

LukasMod commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot deep review

@LukasMod

LukasMod commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 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-09T15:52:20.811491Z 8bf2e72 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.

@MelvinBot

Copy link
Copy Markdown
Contributor

Deep review

No actionable introduced bugs found at fdebccb1d4d76f9ca740c5095e8f24d0b704a622.

Checked:

  • Scoped selectors: changing mention IDs, unrelated updates, hydration, and Search snapshot handling. Mapping work is scoped; underlying collection subscriptions remain.
  • ArrowUp editing: the installed Onyx implementation resolves hydrated cached data, so the suspected slow-read/navigation race was not substantiated.
  • Video-attribute caching: lookup scope matches the HTML being converted; existing cache and edit guards remain unchanged.
  • Concierge pacing: snapshot-based lookup preserves name fallback behavior without changing sequencing or cleanup.

Validation: 9 targeted suites passed, 141 tests passed, covering composer commands, mention maps, Concierge drafts, and video caching.

Non-blocking coverage improvements: test mention A → B → none without store writes; missing names arriving or being deleted; conflicting snapshot/live names; and actual render counts rather than reference identity alone.

Limits: no browser verification or performance profiling in this review. Some composer/video tests mock downstream behavior, so passing tests do not establish complete attachment or offline round-trips.


view run

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: fdebccb1d4

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@LukasMod

LukasMod commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Review

No actionable introduced bugs found at 8bf2e72e856f6a375bc55c1e009229df476f7759.

Rechecked scoped lookups, ArrowUp editing, video caching, and the updated Concierge personal-details ref. No new stale-data or lifecycle regression was substantiated.

Optional robustness improvement: the account extraction guard rejects uppercase mention tags despite the parser accepting them. Making detection consistently case-insensitive would close that mismatch; no actual producer of uppercase tags was found, so this is non-blocking.

Validation: 147 unique tests passed across 9 targeted suites. No browser verification or independent performance profiling performed.


view run

@LukasMod
LukasMod marked this pull request as ready for review November 9, 2026 15:36
@LukasMod
LukasMod requested review from a team as code owners November 9, 2026 15:36
@melvin-bot
melvin-bot Bot requested review from bernhardoj and dylanexpensify and removed request for a team November 9, 2026 15:36
@melvin-bot

melvin-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

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

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.

Can reuse editingReportActionHtml

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.

@LukasMod can you look into this pleasE?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I switched toif (!isEditing)to if (editingReportActionHtml === undefined) {} so it works the same way for empty strings

@bernhardoj

bernhardoj commented Nov 14, 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
  • 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 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 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
    • 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
    • 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 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).
  • 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: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
w.mp4

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

Small NAB suggestion left

@melvin-bot
melvin-bot Bot requested a review from rlinoz November 14, 2026 14:49
@mountiny
mountiny self-requested a review November 16, 2026 04:24
@github-actions
github-actions Bot requested a review from luacmartins November 16, 2026 10:29
@github-actions

Copy link
Copy Markdown
Contributor

This PR adds a new Onyx.get or Onyx.multiGet call, so I've requested a review from the Onyx performance reviewers (@tgolen, @mountiny, @chuckdries, @luacmartins). A review from any one of them is enough. Please check the call against the Onyx.get() rules in ONYX-DATA-MANAGEMENT and ONYX-1.

chuckdries
chuckdries previously approved these changes Nov 16, 2026

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

I approve this usage of Onyx.get 👍

luacmartins
luacmartins previously approved these changes Nov 16, 2026
@luacmartins

Copy link
Copy Markdown
Contributor

@mountiny do you wanna review this one since you're assigned to the issue?

mountiny
mountiny previously approved these changes Nov 17, 2026

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

Yeah changes look good to me, taking over while Rodrigo is out. @LukasMod, can you resolve the conflicts and ping me in slack dm once you do so, so we can avoid more conflicts? thanks!

@LukasMod
LukasMod dismissed stale reviews from mountiny, luacmartins, and chuckdries via 0ae4451 November 17, 2026 08:11
@luacmartins

Copy link
Copy Markdown
Contributor

@LukasMod we have several failing checks

@LukasMod

Copy link
Copy Markdown
Contributor Author

@luacmartins New conflicts resolved, all CI green 👍

@luacmartins
luacmartins merged commit 8e98178 into Expensify:main Nov 17, 2026
36 of 37 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 luacmartins 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/luacmartins 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 optimizes internal mention-name lookups without changing user workflows, labels, or documented behavior.


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.

10 participants