Skip to content

perf: stop keyboard events from re-rendering components that only read the keyboard state in callbacks - #106758

Merged
mountiny merged 4 commits into
Expensify:mainfrom
software-mansion-labs:perf/stop-keyboard-unnecessary-rerenders
Nov 21, 2026
Merged

mountiny merged 4 commits into
Expensify:mainfrom
software-mansion-labs:perf/stop-keyboard-unnecessary-rerenders

Conversation

@jmusial

@jmusial jmusial commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

KeyboardStateProvider updates its context value on every keyboard event, 4 times per open/close. That re-renders every useKeyboardState() consumer, even when the consumer only reads isKeyboardShown inside a callback. The worst case is the Workspaces Table: the Workspaces tab stays mounted while hidden, so all of its rows re-rendered on every keyboard event.

This PR adds useKeyboardShownRef(), a ref with a stable identity that the existing keyboard listeners update, and switches the callback-only readers to it:

  • useScrollToFocusedInput, which lets Table drop its useKeyboardState() subscription
  • ComposerWithSuggestions
  • ConciergePromptBox
  • ReportActionItemMessageEdit

Behaviour is unchanged: the ref is updated on the same events that set isKeyboardShown.

Dev build in the iOS simulator, measured with the React profiler using a 4×ABBA.

Metric Before After Change
Median keyboard-event commit 81.6 ms 22.9 ms −72%
Keyboard commit time per open/close cycle 374 ms 109 ms −71%
keyboard_before_after_side_by_side.mp4

Fixed Issues

$ #106763
PROPOSAL:

Tests

Scenario 1: Search bar in a table

  1. Open the app on iOS or Android
  2. Navigate to Workspaces > any workspace > Members
  3. Tap the "Find member" search bar
  4. Verify that the keyboard opens and the search bar stays visible above it
  5. Type a name and verify that the list filters
  6. Dismiss the keyboard and verify that the table looks the same as before

Scenario 2: Enter key in composers

  1. Open the app on iOS or Android
  2. Navigate to any chat and tap the composer
  3. Type a message and press Return on the on-screen keyboard
  4. Verify that a new line is added and the message is not sent
  5. Navigate to Home, tap the "Ask Concierge anything" box, type text and press Return
  6. Verify that a new line is added and nothing is sent

Offline tests

Same as tests

QA Steps

Same as tests

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

Keyboard events are only on native

Android: Native

https://github.com/user-attachments/assets/eb81743e-a8af-4da2-9ec7-02266f705d46
https://github.com/user-attachments/assets/e4b32d78-5483-40d6-8944-ac9f9f001cf2

iOS: Native

https://github.com/user-attachments/assets/ec1260ff-fa1e-40e2-b7bf-78f44d628cdb
https://github.com/user-attachments/assets/02904e10-54dd-4e7d-92ae-2935703eda47

@jmusial

jmusial commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@codecov

codecov Bot commented Nov 12, 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 Δ
...ListWithSections/BaseSelectionListWithSections.tsx 95.54% <100.00%> (ø)
...List/hooks/useScrollToFocusedInput/index.native.ts 40.00% <100.00%> (-1.67%) ⬇️
src/components/Table/Table.tsx 96.66% <100.00%> (-0.02%) ⬇️
src/components/withKeyboardState.tsx 89.58% <100.00%> (+20.53%) ⬆️
src/hooks/useKeyboardShownRef.ts 100.00% <100.00%> (ø)
...rc/pages/home/ForYouSection/ConciergePromptBox.tsx 95.30% <100.00%> (ø)
...rt/ReportActionCompose/ComposerWithSuggestions.tsx 80.57% <100.00%> (ø)
...pages/inbox/report/ReportActionItemMessageEdit.tsx 61.07% <50.00%> (ø)
... and 36 files with indirect coverage changes

@MelvinBot

MelvinBot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Web test steps verification results: ⚠️ partial

Verified member filtering and multiline draft retention on dev NewDot web. Native keyboard behavior, web Shift+Enter, message editing, and JS-console cleanliness remain unverified.

Home composer retaining a two-line draft

Step Status
S1.1 Open app on iOS or AndroidWeb-only session.
⚠️
S1.2 Navigate Workspaces → workspace → MembersMembers page, searchbox, and owner row appeared.
✅
S1.3 Focus Find memberSearch accepted text and updated results.
✅
S1.4 Keyboard opens; search stays visibleNative keyboard unavailable on web.
⚠️
S1.5 Type a name; list filtersMatching text showed the owner; unmatched text showed “No results found”; restoring matching text restored the row.
Members search with matching owner row
✅
S1.6 Dismiss keyboard; table unchangedNative keyboard dismissal unavailable on web.
⚠️
S2.1 Open app on iOS or AndroidWeb-only session.
⚠️
S2.2 Navigate to chat and focus composerOpened Concierge chat and entered a draft.
✅
S2.3 Press Return on on-screen keyboardNative keyboard unavailable; desktop Enter was not substituted.
⚠️
S2.4 Return adds newline without sendingReturn and Shift+Enter were not exercised. Multiline text entry retained two lines without sending.
⚠️
S2.5 Home → Ask Concierge anything → type and press ReturnComposer accepted text; Return and Shift+Enter remain unverified.
⚠️
S2.6 Newline added; nothing sentMultiline text entry retained two lines without sending, but keyboard-triggered newline behavior remains unverified.
Home composer retaining a two-line draft
⚠️
Message editing smoke testNot reached within the interaction budget after navigation fallbacks.
⚠️
QA: No JS-console errorsAvailable browser tooling did not expose console inspection.
⚠️

view run · view recording

@jmusial
jmusial marked this pull request as ready for review November 13, 2026 13:57
@jmusial
jmusial requested review from a team as code owners November 13, 2026 13:57
@melvin-bot
melvin-bot Bot requested review from thesahindia and removed request for a team November 13, 2026 13:58
@melvin-bot

melvin-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

@thesahindia 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 dylanexpensify and removed request for a team November 13, 2026 13:58
@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-13T14:19:52.083917Z 17249ec 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.

@dylanexpensify dylanexpensify 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 input not required for this PR.

@jmusial

jmusial commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@thesahindia kind bump

@thesahindia

thesahindia commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

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
Screen.Recording.2026-11-19.at.3.34.57.PM.mov
Screen.Recording.2026-11-19.at.3.36.51.PM.mov
Android: mWeb Chrome
Screen.Recording.2026-11-19.at.3.41.04.PM.mov
iOS: HybridApp
Screen.Recording.2026-11-19.at.4.04.10.PM.mov
Screen.Recording.2026-11-19.at.4.04.44.PM.mov
iOS: mWeb Safari
Screen.Recording.2026-11-19.at.4.05.32.PM.mov
MacOS: Chrome / Safari Screenshot 2026-11-19 at 3 43 10 PM

@thesahindia thesahindia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@melvin-bot
melvin-bot Bot requested a review from mountiny November 19, 2026 11:26
@mountiny
mountiny merged commit b4333ed into Expensify:main Nov 21, 2026
37 of 39 checks passed
@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

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

@github-actions

Copy link
Copy Markdown
Contributor

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.5.53-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed — this PR optimizes keyboard-event rendering without changing user-facing workflows, UI labels, or behavior, so existing help articles remain accurate.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/arosiclair in version: 9.5.53-3 🚀

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