Repository navigation
Description
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:
- 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.
- Build the mechanism in ButtonComposed. This is a single PR that everything else builds on. POC PR
- 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.
- Verify each label the same way Introduce the spinner on the
FormAlertWithSubmitButtonbuttons #92498 was verified: the Sentry query per data-sentry-label, INP span count plus the badness score. - 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 Owner
Current Issue Owner: @marufsharifiMetadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
OlGierd03 commentedon Aug 27, 2026
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
rlinoz commentedon Sep 1, 2026
Not overdue, PR in progress
melvin-bot commentedon Sep 4, 2026
@OlGierd03 Whoops! This issue is 2 days overdue. Let's get this updated quick!
melvin-bot commentedon Sep 5, 2026
@OlGierd03 Whoops! This issue is 2 days overdue. Let's get this updated quick!
OlGierd03 commentedon Sep 5, 2026
PR containing the core changes for the Instant Spinner is currently undergoing an internal review
43 remaining items
melvin-bot commentedon Nov 9, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)mallenexpensify commentedon Nov 9, 2026
Payment Summary
Contributor+: @marufsharifi due $275 via Upwork.
Bumping to weekly and making you owner @marufsharifi
marufsharifi commentedon Nov 10, 2026
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
ButtonComposedand migrate buttons. The delivered PR also refactored shared, app-wide infrastructure — it splitButtonContextinto state/actions contexts, rewroteusePressLoading(press guard, error logging, focus-based reset), splitConfirmButtonOptions.onConfirm, and moved submit-button loading out ofFormAlertWithSubmitButton. 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
POCand 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
usePressLoadingtest. Diff: https://github.com/Expensify/App/pull/99326/filesCore flow changes:
Button,usePressLoading, andFormProvider/FormAlertWithSubmitButtonback every button and form in the app — the highest-risk surface — so verification required far broader testing than a standard PR.rlinoz commentedon Nov 10, 2026
To be fair the changes were pretty similar among themselves and half of the PR were tests, I suggest a 1.5x increase.
mallenexpensify commentedon Nov 11, 2026
Updated to $275, paying once can pay via Upwork.
rlinoz commentedon Nov 11, 2026
Hey @OlGierd03 is the plan that we will migrate some buttons to use the spinner? Should we create issues for those?
OlGierd03 commentedon Nov 12, 2026
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.
rlinoz commentedon Nov 12, 2026
Agents might 😄
Your plan sounds great, thanks!