Skip to content

[No QA][INP] Improve UserListItem-Checkbox INP: paint the checkmark optimistically and run the selection update as a transition - #97140

Open
dilshodmackbook-sketch wants to merge 4 commits into
Expensify:mainfrom
dilshodmackbook-sketch:dilshod/fix-94722-checkbox-inp
Open

[No QA][INP] Improve UserListItem-Checkbox INP: paint the checkmark optimistically and run the selection update as a transition#97140
dilshodmackbook-sketch wants to merge 4 commits into
Expensify:mainfrom
dilshodmackbook-sketch:dilshod/fix-94722-checkbox-inp

Conversation

@dilshodmackbook-sketch

@dilshodmackbook-sketch dilshodmackbook-sketch commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Improves the INP of the UserListItem-Checkbox interaction (the selection checkbox on user/list rows). Profiling on a production build (2,000 contacts, /new/chat group multi-select, 4x CPU throttle) showed the tap's next paint is blocked by a single ~51 ms React commit: the selection state update re-runs the whole options pipeline (getValidOptions -> filterAndOrderOptions -> section flattening -> every visible row re-render) synchronously before the toggled checkmark can be shown.

The change splits the tap into an urgent, tiny update and a deferred one — the same urgent-feedback + startTransition split used for the PrevNextButtons-NextButton INP issue (#94721, PR #95737):

  1. ListSelectionButton — the checkmark is painted optimistically on press via local state, so it flips on the tap frame even while the parent's selection update is still pending. The optimistic value is dropped as soon as the item.isSelected prop catches up (state-adjustment-during-render, per the React docs). Since this component backs every SelectionList checkbox/radio, the instant feedback applies app-wide.
  2. NewChatPage.toggleOption — the heavy selection update (setSelectedOptions + setGroupDraft) now runs inside startTransition, so the full pipeline re-render lands one frame later without blocking the tap's paint. Membership is read from a ref tracking the latest selection so back-to-back toggles compose off the newest list instead of a stale render snapshot while a previous transition is still catching up.

The change is behavior-preserving: selection results, group draft contents, search clearing, and focus handling are unchanged; only the scheduling of the re-render moves.

Metrics improvement

Interaction: UserListItem-Checkbox (data-sentry-label).

Captured on a production (staging) web build with the INP-approximating window from the INP Improvement Workflow — 10 samples before and 10 after, /new/chat group multi-select seeded with 2,000 contacts under 4x CPU throttle (recording starts on the checkbox press and stops on the next animation frame after the click):

Average total duration
Before (main) 57.57 ms
After (this PR) 16.75 ms
Diff -40.82 ms (-70.9%)

The ~51 ms options-pipeline commit is moved off the tap frame (optimistic checkmark + startTransition), so the toggled checkmark paints on the press frame and the heavy selection re-render commits one frame later. Selection results are unchanged, so there is no visual or behavioral regression. Full trace details are in this comment.

React Profiler comparator

React Profiler comparator summary

Fixed Issues

$ #94722
PROPOSAL: #94722 (comment)

Tests

  1. Go to FAB > Start chat.
  2. Press "Add to group" on a contact.
  3. Verify the row shows a checked checkbox and the "Next" button appears.
  4. Tap the checkbox of the selected contact to unselect it, then select it again — verify the checkmark toggles instantly on every tap and the selection state (rows, "Next" button) stays correct.
  5. Rapidly tap the same contact's checkbox several times in a row — verify the final checked state matches the number of taps (even taps = unselected, odd = selected) and no contact is duplicated or stuck.
  6. Add several contacts to the group, type in the search field, select/unselect from the filtered results — verify search clearing and selection behave as before.
  7. Continue to the group confirmation page and create the group — verify all selected members are present.
  • Verify that no errors appear in the JS console

Offline tests

Same as Tests — the change only affects render scheduling of local selection state; no network calls are involved. Selection must behave identically while offline.

QA Steps

[No QA] — performance-only change with no user-facing behavior change. The interaction produces the same result in the same order; only the scheduling relative to paint changes, verified by the before/after React Profiler metrics above and the Tests section.

  • 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-28.at.18.43.13.mov
Android: mWeb Chrome
94722-android-mweb-chrome.mp4
iOS: Native
Screen.Recording.2026-07-28.at.19.08.18.mov
iOS: mWeb Safari
94722-ios-mweb-safari.mp4
MacOS: Chrome / Safari
94722-macos-chrome.mp4

@dilshodmackbook-sketch dilshodmackbook-sketch changed the title Improve UserListItem-Checkbox INP: paint the checkmark optimistically and run the selection update as a transition [No QA][INP] Improve UserListItem-Checkbox INP: paint the checkmark optimistically and run the selection update as a transition Jul 28, 2026
@dilshodmackbook-sketch
dilshodmackbook-sketch marked this pull request as ready for review July 28, 2026 07:58
@dilshodmackbook-sketch
dilshodmackbook-sketch requested review from a team as code owners July 28, 2026 07:58
@melvin-bot
melvin-bot Bot requested a review from aimane-chnaif July 28, 2026 07:59
@melvin-bot

melvin-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

@aimane-chnaif 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 joekaufmanexpensify and removed request for a team July 28, 2026 07:59
@dilshodmackbook-sketch

Copy link
Copy Markdown
Contributor Author

@codex review

@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: df2eb9eb10

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

onPress={() => onSelectRow(item)}
isChecked={isChecked}
onPress={() => {
setOptimisticChecked(!isChecked);

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 Preserve checked state for selected radio rows

Because this shared button also backs ListRadioButton, tapping an already-selected radio now runs setOptimisticChecked(!isChecked) and immediately renders it unchecked. In single-select pickers that stay on the page and leave the value unchanged on a repeated tap (for example the spend rule merchant match-type selector, whose handler just calls setMatchType(item.value)), item.isSelected never changes, so the reset block does not run and the selected radio remains visually unchecked until another option/remount changes the prop. Restrict this optimistic toggle to checkboxes or avoid inverting an already-checked radio.

Useful? React with 👍 / 👎.

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.

Good catch. Fixed in the latest commit. Since a radio press only ever selects (never toggles off), the optimistic paint now sets true for radios instead of inverting the current value, so re-pressing an already-selected radio keeps it checked. Only checkboxes flip. Added a unit test covering the re-press-selected-radio case.

dilshodmackbook-sketch and others added 2 commits July 28, 2026 13:09
The optimistic checkmark also backs radio rows. Re-pressing an already-
selected radio inverted it to unchecked, and since its isSelected prop
never changes the reset never fired, leaving it stuck unchecked. A radio
press only ever selects, so paint it checked instead of toggling.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
...s/SelectionList/components/ListSelectionButton.tsx 100.00% <100.00%> (ø)
src/pages/NewChatPage/index.tsx 79.86% <90.00%> (+1.39%) ⬆️
... and 49 files with indirect coverage changes

@dilshodmackbook-sketch

Copy link
Copy Markdown
Contributor Author

@codex review

@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: d136ff4b4c

ℹ️ 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 on lines +351 to +352
startTransition(() => {
setSelectedOptions(newSelectedOptions);

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 Build the draft from the latest selection

When a user already has at least one selected member, the Next button remains tappable while this new transition is still pending. In the slow-list case this change targets, tapping “Add to group” for another user and then quickly tapping Next can run createGroup from the previous render, which rebuilds NEW_GROUP_CHAT_DRAFT from stale selectedOptions and can overwrite the draft without the just-added participant. Use latestSelectedOptionsRef.current for confirmation, or otherwise prevent confirmation until the deferred selection has committed.

Useful? React with 👍 / 👎.

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.

Good catch. Fixed - createGroup now reads from latestSelectedOptionsRef.current instead of the render snapshot, so tapping "Add to group" and then quickly tapping Next while the deferred selection transition is still pending rebuilds the draft from the newest list (including the just-added participant), rather than a stale selectedOptions.

Comment on lines +59 to +62
if (prevCheckedProp !== isCheckedProp) {
setPrevCheckedProp(isCheckedProp);
setOptimisticChecked(null);
}

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 Reset optimistic checks when rows are recycled

This reset only watches item.isSelected, so an optimistic value survives if the same component instance receives a different item with the same selected state. SelectionList rows are rendered through FlashList and can be recycled during filtering/scrolling; after pressing an unchecked row, a recycled cell for another unchecked row will keep optimisticChecked === true and display the wrong checkmark until some later selection prop change. Track item.keyForList/identity as part of the reset as well.

Useful? React with 👍 / 👎.

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.

Good catch. Fixed - the reset now tracks item.keyForList identity alongside isSelected, so when FlashList recycles a cell to a different item with the same selected state the stale optimisticChecked is dropped instead of leaking onto the recycled row. Added a unit test covering the recycle-to-different-item case.

… latest selection

Address two Codex P2 findings:
- ListSelectionButton: the optimistic-check reset only watched item.isSelected,
  so a FlashList-recycled cell could keep a stale optimisticChecked=true and show
  the wrong checkmark. Track item.keyForList identity in the reset too.
- NewChatPage.createGroup: read from latestSelectedOptionsRef so tapping "Add to
  group" then quickly Next (while the deferred selection transition is still
  pending) doesn't rebuild the draft from a stale selectedOptions snapshot.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@joekaufmanexpensify

Copy link
Copy Markdown
Contributor

No product review needed.

@joekaufmanexpensify
joekaufmanexpensify removed their request for review July 28, 2026 20:59
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