Skip to content

[Due for payment 2026-11-05]Show a spinner the instant any heavy button is pressed #99659

Open

Description

@rlinoz

From https://expensify.slack.com/archives/C08CZDJFJ77/p1787675298864849

Background:
In many places the UI is slow to respond to user actions. We measure this with INP (Interaction to Next Paint, the time from a user's tap to the next frame painted). The industry threshold for a "good" interaction is 200 ms; across our production environment over the last 14 days, the 75th-percentile INP is 399 ms.

An interaction's INP can be improved in two ways:

• make the work behind it cheaper by optimizing the code,.
• paint visual feedback sooner: by deferring the work until after the next paint or by introducing a loading state before the work runs..
We have already started on both fronts.

Today, in most of the app, the only spinner mechanism is a plain isLoading prop on ButtonComposed, driven by Onyx: the press handler flips it with a write like Onyx.merge(formID, {isLoading: true}) alongside the rest of the API call's optimistic data. That write is asynchronous and batched, so useOnyx notifies subscribers only after the handler's synchronous work is done (validation, building optimistic data, etc.) and React then re-renders every component subscribed to the touched keys in the same pass as the button. The spinner therefore paints only after the work it was meant to cover has partially completed.

The app also has a newer mechanism, currently limited to form submit buttons: the usePressLoading hook introduced in PR #92498 and wired into FormAlertWithSubmitButton. It inverts the order of operations: on press it commits a local loading state, lets React paint the spinner and only then, one macrotask later, runs the real handler, handing over to the Onyx-driven isLoading (where one exists) with no flicker.

Problem:
Buttons in the app freeze the UI with no response for 400+ ms, even in places where a spinner is already wired up via isLoading, leaving the user doubting whether the tap registered.

Solution:
Give ButtonComposed its own immediate loading state, so any button that can leave the user waiting 200+ ms acknowledges the tap within a frame. The mechanism lives in ButtonComposed and follows the same paint-first-then-run order proven by usePressLoading. The difference is that the state and the deferral live inside button, so a consumer opts in instead of wiring a hook.

The plan would look like this:

  1. Build an inventory of buttons that can benefit from migration. Start from the labels in Sentry's INP attribution and fill gaps with a code audit of ButtonComposed usages.
  2. Build the mechanism in ButtonComposed. This is a single PR that everything else builds on. POC PR
  3. Migrate in order of user impact, ranked by current INP span counts per label. Mainly a flag flip. Handlers that validate in onPress receive the button's startWithLoading callback, so the spinner starts only when validation passes and real work begins, with no flicker.
  4. Verify each label the same way Introduce the spinner on the FormAlertWithSubmitButton buttons #92498 was verified: the Sentry query per data-sentry-label, INP span count plus the badness score.
  5. Optional: make the immediate loading state the default for all new buttons, opt-out through the same prop.

This solves the problem directly: the user's tap is acknowledged within a frame, so the press never feels sluggish and the spinner honestly communicates "working on it" for however long the unavoidable work takes. Optimizing the underlying Onyx writes and re-renders remains worthwhile, but it's a long, per-flow effort. This proposal makes every consequential button trustworthy now, with a proven, drop-in mechanism.

Benefits:
Sentry INP spans count attributed to Form-SubmitButton (via data-sentry-label) dropped ~90% and the badness score flatlined to near zero, with hard break exactly at the 16 Jul usePressLoading deploy. Since Sentry usually records only a session's single worst interaction, 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.

Issue OwnerCurrent Issue Owner: @marufsharifi

Activity

  1. OlGierd03 commented on Aug 27, 2026

    @OlGierd03
    Contributor

    Issues #96058 and #96125 were raised after the immediate spinner on the Form-SubmitButton PR was merged and should be taken into account during the migration process

  2. rlinoz commented on Sep 1, 2026

    @rlinoz
    ContributorAuthor

    Not overdue, PR in progress

  3. melvin-bot commented on Sep 4, 2026

    @melvin-bot

    @OlGierd03 Whoops! This issue is 2 days overdue. Let's get this updated quick!

  4. melvin-bot commented on Sep 5, 2026

    @melvin-bot

    @OlGierd03 Whoops! This issue is 2 days overdue. Let's get this updated quick!

  5. OlGierd03 commented on Sep 5, 2026

    @OlGierd03
    Contributor

    PR containing the core changes for the Instant Spinner is currently undergoing an internal review

  6. 43 remaining items

  7. melvin-bot commented on Nov 9, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  8. mallenexpensify commented on Nov 9, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @marufsharifi due $275 via Upwork.

    Bumping to weekly and making you owner @marufsharifi

  9. marufsharifi commented on Nov 10, 2026

    @marufsharifi

    Price increase request

    Mandatory

    Proposed amount: $350 (2× the $175)

    Why the work exceeded the issue: The issue asked to build the immediate-loading mechanism into ButtonComposed and migrate buttons. The delivered PR also refactored shared, app-wide infrastructure — it split ButtonContext into state/actions contexts, rewrote usePressLoading (press guard, error logging, focus-based reset), split ConfirmButtonOptions.onConfirm, and moved submit-button loading out of FormAlertWithSubmitButton. Reviewing it meant verifying a high-blast-radius change to every button and form in the app, not a localized feature.

    Regressions caused by this PR: None.

    Optional

    Scope expansion: The PR began as a POC and grew into mechanism + core refactor + button migrations (Search bulk edit, NewChat, and the accountant/attendee/participant IOU selectors).

    Files touched: 24 files, ~+746 / −171. 18 source across Button, Form, SelectionList, hooks, and IOU/Search/NewChat pages, plus 6 test files including a new 355-line usePressLoading test. Diff: https://github.com/Expensify/App/pull/99326/files

    Core flow changes: Button, usePressLoading, and FormProvider / FormAlertWithSubmitButton back every button and form in the app — the highest-risk surface — so verification required far broader testing than a standard PR.

  10. rlinoz commented on Nov 10, 2026

    @rlinoz
    ContributorAuthor

    To be fair the changes were pretty similar among themselves and half of the PR were tests, I suggest a 1.5x increase.

  11. mallenexpensify commented on Nov 11, 2026

    @mallenexpensify
    Contributor

    Updated to $275, paying once can pay via Upwork.

  12. rlinoz commented on Nov 11, 2026

    @rlinoz
    ContributorAuthor

    Hey @OlGierd03 is the plan that we will migrate some buttons to use the spinner? Should we create issues for those?

  13. OlGierd03 commented on Nov 12, 2026

    @OlGierd03
    Contributor

    Yeah, that's the idea. #99326 covered the mechanism plus some of the more problematic buttons along the way, but there are still many others we can migrate.

    I'll suggest how to split the remaining buttons into batches and get back to you. Then we can open the issues and decide together which ones could go to contributors and which ones I should take.

    I think it'd be good if I first set the pattern directly in the code in a few more places, so the later migrations have a solid reference to follow. In theory we could write up a description of the migration pattern, but I doubt anyone would actually read it.

  14. rlinoz commented on Nov 12, 2026

    @rlinoz
    ContributorAuthor

    In theory we could write up a description of the migration pattern, but I doubt anyone would actually read it.

    Agents might 😄

    Your plan sounds great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2ExternalAdded to denote the issue can be worked on by a contributorTask

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions