Skip to content

[Payment due @marufsharifi] Introduce immediate spinner to ButtonCompose - #99326

Merged
rlinoz merged 31 commits into
Expensify:mainfrom
software-mansion-labs:@OlGierd03/POC-ButtonCompose-instant-spinner
Oct 27, 2026
Merged

rlinoz merged 31 commits into
Expensify:mainfrom
software-mansion-labs:@OlGierd03/POC-ButtonCompose-instant-spinner

Conversation

@OlGierd03

@OlGierd03 OlGierd03 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Adds an opt-in immediate loading state to ButtonComposed, so a press is acknowledged within a frame instead of after the handler's blocking work. The new shouldShowLoadingImmediatelyOnPress prop wraps the whole onPress: Button commits a local pressed state, lets React paint the spinner, then runs the handler one macrotask later and hands over to the Onyx-driven isLoading (where one exists) with no flicker. Turning it on is a one-line change at the call site.

For handlers that validate or branch before doing the work, we use usePressLoading explicitly, so the handler calls startWithLoading only on the branch that actually starts work. A press that fails validation never calls run, so it shows no spinner and can't get stuck.

The same mechanism already shipped for form submits in #92498, and the chart below shows why it's worth spreading: daily INP spans for [data-sentry-label="Form-SubmitButton"] fall from 1K to 1.7K to near zero at the 16 Jul deploy, with the badness score flatlining on the same date (the single badness spike on 14 Aug is an unrelated anomaly):

improvement

Sentry usually records only a session's single worst INP interaction, so each of those spans meant "submitting a form was the slowest thing this user did all session"; that stopped being true for thousands of sessions a week

Button hands startWithLoading to onPress as a second argument, so a branching handler can spin only on the branch that starts work without wiring up its own usePressLoading. That argument slot was already taken on selection lists, so ConfirmButtonOptions.onConfirm is split into onConfirm(event) for the selection and a new onConfirmFocusedOption(option) for the lists where confirming acts on a single row.

Additionally, ButtonContext is split into a state and an actions context (rulesdir/context-provider-split-values), since the onPress published to the primitives is now the wrapped handler.

usePressLoading itself now backs this Button-level wrapping (and FormProvider/FormAlertWithSubmitButton, which delegate their spinner to Button instead of owning a second instance). An undefined isLoading means there is no flag to hand over to, so the spinner clears as soon as the handler settles unless it navigated away, in which case the focus reset clears it on return and a synchronous in-flight guard ignores a second press landing before React commits the pressed state.

Fixed Issues

#99659

Tests

  1. Open an expense report.
  2. Enter the selection mode and select several expenses (the more, the better because the JS thread block on save is easier to observe).
  3. Press Edit multiple in the selection menu.
  4. In the Edit multiple expenses RHP, open any field (e.g. Description), set a new value and press Save on the field page.
  5. Back on the Edit multiple expenses page, press Save.
  6. Verify the spinner appears on Save the instant it is pressed, before the RHP freezes/dismisses, and that it stays visible until the RHP is dismissed (no frame without the spinner).
  7. Verify the edited value is applied to all selected expenses.

Additionally run the test steps from #92498 as well, since this PR reworks the usePressLoading hook and the FormProvider/FormAlertWithSubmitButton flows that PR introduced. Verify none of them regress (spinner appears on press, clears after validation errors, never gets stuck after navigating back and a double press submits only once).

Offline tests

N/A

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 followed proper code patterns (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 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 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 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

Before:

before_1.mov

After:

after_1.mov

@codecov

codecov Bot commented Aug 24, 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/components/Button/Button.tsx 100.00% <100.00%> (ø)
src/components/Button/primitives/ButtonIcon.tsx 92.30% <100.00%> (ø)
...Button/primitives/ButtonKeyboardShortcut/index.tsx 100.00% <100.00%> (ø)
src/components/Button/primitives/ButtonText.tsx 100.00% <100.00%> (ø)
src/components/FormAlertWithSubmitButton.tsx 96.66% <ø> (-0.48%) ⬇️
...s/SelectionList/hooks/useSelectionListShortcuts.ts 100.00% <100.00%> (ø)
src/pages/NewChatPage/index.tsx 82.70% <100.00%> (+0.13%) ⬆️
...ges/iou/request/MoneyRequestAccountantSelector.tsx 0.00% <ø> (ø)
src/components/Button/context/ButtonContext.ts 85.71% <85.71%> (+10.71%) ⬆️
src/hooks/usePressLoading.ts 95.65% <94.11%> (+22.92%) ⬆️
... and 4 more
... and 15 files with indirect coverage changes

@OlGierd03 OlGierd03 changed the title [POC] Introduce immediate spinner to ButtonCompose Introduce immediate spinner to ButtonCompose Sep 4, 2026

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

Great work! I think that this problem needs to be addressed though.

Comment thread src/hooks/usePressLoading.ts Resolved
@OlGierd03
OlGierd03 marked this pull request as ready for review September 8, 2026 17:20
@OlGierd03
OlGierd03 requested review from a team as code owners September 8, 2026 17:20
@melvin-bot
melvin-bot Bot requested review from JmillsExpensify and amyevans and removed request for a team September 8, 2026 17:20
@melvin-bot

melvin-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

@amyevans 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 September 8, 2026 17:21
Comment thread src/components/Button/context/types.ts Resolved
Comment thread src/components/Button/context/types.ts Resolved

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

ℹ️ 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/usePressLoading.ts Resolved
@amyevans
amyevans requested review from rlinoz and removed request for amyevans September 8, 2026 17:57
@rlinoz
rlinoz requested a review from marufsharifi September 8, 2026 19:13
JmillsExpensify
JmillsExpensify previously approved these changes Sep 9, 2026

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

LGTM

@OlGierd03

Copy link
Copy Markdown
Contributor Author

I will address the review comments shortly, currently focusing on other high-priority project

@marufsharifi

marufsharifi commented Sep 9, 2026 •

Copy link
Copy Markdown

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

Android: HybridApp
Screen.Recording.2026-09-09.at.4.56.32.PM.mov
Android: mWeb Chrome
Recording_20260909_163235.mp4
iOS: HybridApp
Screen.Recording.2026-09-09.at.5.15.31.PM.mov
iOS: mWeb Safari
Screen.Recording.2026-09-09.at.5.03.00.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-09-09.at.3.56.44.PM.mov

@rlinoz

rlinoz commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Hey @marufsharifi anything left here?

@OlGierd03

OlGierd03 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

BUG:. I manually constructed a deep link to the Add work email page using the Company Cards workspace URL and an invalid card feed ID (QA_INVALID_FEED). After entering a verified work email and clicking Save, the button remained stuck in a loading state, with the spinner continuing indefinitely.

@marufsharifi addressed, thanks for the catch. The hook now clears the spinner one frame after the handler finishes if nothing took over.

Note that on main Save button also does nothing visible here (no error for the invalid feed), that's existing page behavior so I'm leaving it out of this PR.

Please feel free to continue your review. One ask for the next pass. Looking back, the bugs from the last rounds all go back to the first version of the hook, not to the later fixes, so I'm a bit worried we'll keep finding them one at a time. Could you do a full sweep this time and put everything you find in one review, even small stuff? I'll fix it all in one go.

@rlinoz
rlinoz requested a review from marufsharifi October 22, 2026 17:21

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

LGTM

@melvin-bot melvin-bot Bot changed the title Introduce immediate spinner to ButtonCompose [Payment due @marufsharifi] Introduce immediate spinner to ButtonCompose Oct 23, 2026
@melvin-bot

melvin-bot Bot commented Oct 23, 2026

Copy link
Copy Markdown

🎯 @marufsharifi, thanks for reviewing and testing this PR! 🎉

A payment issue will be created for your review once this PR is deployed to production.
E/E issue linked to the PR - no internal issue.

If payment is not needed (e.g., regression PR review fix etc), react with 👎 to this comment to prevent the payment issue from being created.

Comment thread src/hooks/usePressLoading.ts Resolved
Comment thread src/components/Button/context/types.ts Resolved
Comment thread src/components/Button/context/types.ts Resolved
@OlGierd03

Copy link
Copy Markdown
Contributor Author

@rlinoz review addressed!

rlinoz
rlinoz previously approved these changes Oct 26, 2026

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

Thanks!

@rlinoz

rlinoz commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

@OlGierd03 is the perf test failing related?

@OlGierd03

OlGierd03 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

is the perf test failing related?

I don't think so. I'll merge main to re-run the check

Edit: All green now 💚

@OlGierd03
OlGierd03 force-pushed the @OlGierd03/POC-ButtonCompose-instant-spinner branch from 3342c96 to 76ddd51 Compare October 27, 2026 07:31
@OlGierd03
OlGierd03 force-pushed the @OlGierd03/POC-ButtonCompose-instant-spinner branch from 76ddd51 to 8cc5740 Compare October 27, 2026 07:50
@rlinoz
rlinoz merged commit 6cc2875 into Expensify:main Oct 27, 2026
35 of 36 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 rlinoz 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

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/rlinoz in version: 9.5.24-1 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update is needed. This PR only changes when the loading spinner appears on buttons like Save. That is a loading-behavior detail, and it doesn't change any feature, label, or step described in the help articles.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/jasperhuangg in version: 9.5.24-8 🚀

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

Bundle Size Analysis (Sentry):

@melvin-bot

melvin-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

🤖 Payment issue created: #105314

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.

7 participants