Skip to content

[Due for payment 2026-07-23] [INP] Slow Form-SubmitButton #85596

Closed
1 of 1 issue completed
Closed

Description

@rlinoz

In an effort to improve the #quality of our app we started looking at INP (interaction to next pain) and looking at our slowest INPs we have [data-sentry-label=“Form-SubmitButton”]

Let's investigate why it is slow and fix it.

Issue OwnerCurrent Issue Owner: @rojiphil
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022034008884287958380
  • Upwork Job ID: 2034008884287958380
  • Last Price Increase: 2026-03-17

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 17, 2026
  2. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Mar 17, 2026
  3. melvin-bot commented on Mar 17, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @ShridharGoel (External)

  4. changed the title [-][INP] Slow Form-SubmitButton[/-] [+][$250] [INP] Slow Form-SubmitButton[/+] on Mar 17, 2026
  5. melvin-bot commented on Mar 17, 2026

    @melvin-bot
  6. MelvinBot commented on Mar 17, 2026

    @MelvinBot
    Contributor

    I have failed to help you. I let you down and for that I am sorry. Please try again later. This may be due to a Claude outage (check here).

    Failure details: https://github.com/Expensify/Expensify/actions/runs/23215718760

  7. jainam884 commented on Mar 17, 2026

    @jainam884

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    The interaction tagged as Form-SubmitButton has high INP. When a user taps submit while focused in a form field, the submit path feels delayed before the form transitions into the submit/loading flow.

    What is the root cause of that problem?

    In FormProvider.submit(), we currently wait for KeyboardUtils.dismiss() to resolve before calling onSubmit.

    // Return early if the form is already submitting to avoid duplicate submission
    if (!!formState?.isLoading || isLoading) {
    return;
    }
    // Prepare values before submitting
    const trimmedStringValues = shouldTrimValues ? prepareValues(inputValues) : inputValues;
    // Touches all form inputs, so we can validate the entire form
    for (const inputID of Object.keys(inputRefs.current)) {
    touchedInputs.current[inputID] = true;
    }
    if (hasServerError) {
    return;
    }
    // Validate form and return early if any errors are found
    if (!isEmptyObject(onValidate(trimmedStringValues))) {
    return;
    }
    // Do not submit form if network is offline and the form is not enabled when offline
    if (network?.isOffline && !enabledWhenOffline) {
    return;
    }
    KeyboardUtils.dismiss().then(() => onSubmit(trimmedStringValues));
    }, [enabledWhenOffline, formState?.isLoading, inputValues, isLoading, network?.isOffline, onSubmit, onValidate, shouldTrimValues, hasServerError]),
    1000,
    {leading: true, trailing: false},

    When the keyboard is visible, dismiss() resolves only after keyboard-hide events/viewport resize handling, so submit kickoff is blocked behind keyboard dismissal instead of starting immediately.

    const dismiss = (shouldSkipSafari?: boolean): Promise<void> => {
    return new Promise((resolve) => {
    if (!isVisible) {
    resolve();
    return;
    }
    const subscription = Keyboard.addListener('keyboardDidHide', () => {
    resolve();
    subscription.remove();
    });
    Keyboard.dismiss();
    });
    };

    const dismiss = (shouldSkipSafari = false): Promise<void> => {
    return new Promise((resolve) => {
    if (shouldSkipSafari && isMobileSafari()) {
    resolve();
    return;
    }
    if (!isVisible || !isMobile()) {
    resolve();
    return;
    }
    const handleDismissResize = () => {
    const viewportHeight = window?.visualViewport?.height;
    if (!viewportHeight || !initialViewportHeight) {
    return;
    }
    const isKeyboardVisible = initialViewportHeight - viewportHeight > CONST.SMART_BANNER_HEIGHT;
    if (isKeyboardVisible) {
    return;
    }
    window.visualViewport?.removeEventListener('resize', handleDismissResize);
    return resolve();
    };
    window.visualViewport?.addEventListener('resize', handleDismissResize);
    Keyboard.dismiss();
    });
    };

    Assumption: on web, clicking submit can also trigger input blur validation and then full submit validation in the same interaction window, adding extra main-thread work around the same tap.

    What changes do you think we should make in order to solve the problem?

    1. In FormProvider.submit(), replace KeyboardUtils.dismiss().then(() => onSubmit(values)) with KeyboardUtils.dismissKeyboardAndExecute(() => onSubmit(values)).
    2. Make submit-click blur prevention the default for forms (shouldPreventDefaultFocusOnPressSubmit = true in FormProvider/FormWrapper) so a submit click does not trigger an extra blur validation pass before submit.
    3. Add a small submit-path performance measurement (validate time vs submit kickoff time) behind the same submit label so we can verify the INP drop after deployment.

    What alternative solutions did you explore? (Optional)

    I considered only optimizing individual forms that appear in Sentry traces, but this is a shared form-submit path used widely, so a central fix in FormProvider is safer and gives broader impact.

    I also considered deferring validation with timers/idle callbacks, but that would delay error feedback and create inconsistent behavior across platforms.

  8. mendarb commented on Mar 17, 2026

    @mendarb

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    The Form-SubmitButton interaction has a high INP score (>500ms at p75). When users tap submit on any form, the browser blocks painting for too long before showing visual feedback, creating a sluggish feel.

    What is the root cause of that problem?

    The submit handler in FormProvider.tsx performs multiple synchronous blocking operations before yielding to the browser:

    1. onValidate → errors → onValidate dependency cycle: onValidate (line ~144) includes errors in its dependency array (line 205). Each validation call may setErrors, which changes errors, which recreates onValidate, which recreates submit, which recreates registerInput — causing all form inputs to re-render in a cascade before the next paint.

    2. Synchronous validation in submit path: submit (line ~255) calls onValidate(trimmedStringValues) synchronously and checks its return inline. The validation iterates all input values, runs prepareValues (string trimming), performs HTML tag regex matching on every field, and calls setErrors — all blocking the main thread during the press event.

    3. registerInput recreated too often: It depends on errors, inputValues, draftValues, formState?.errorFields, onValidate, and submit (line ~460). Any change to any of these triggers a new callback, forcing every registered input to receive new props and re-render.

    4. Un-memoized FormAlertWithSubmitButton: It is a plain function component (no React.memo), so it re-renders every time FormWrapper re-renders, even when its own props are unchanged.

    5. withNavigationFallback HOC on Button: Every Button render goes through this un-memoized HOC layer (line 551 of Button/index.tsx), adding overhead via the useIsFocused() hook.

    What changes do you think we should make in order to solve the problem?

    1. Break the onValidate → errors cycle: Replace errors in onValidates dependency array with a ref (errorsRef.current). Validation only needs the current error values for comparison, not reactivity — a ref avoids the cascade.

    2. Defer validation off the critical path: Wrap the onValidate call inside submit with InteractionManager.runAfterInteractions() so the button press visual feedback paints first, then validation runs. Show immediate visual feedback (loading state) before starting validation.

    3. Wrap FormAlertWithSubmitButton in React.memo and stabilize its callback props (onSubmit, onFixTheErrorsLinkPressed) with useCallback in FormWrapper.

    4. Memoize the SubmitButton JSX in FormWrapper using useMemo instead of the current inline const SubmitButton = isSubmitButtonVisible && (...) which creates a new element tree every render.

    5. Stabilize registerInput by moving inputValues and errors reads to refs where they are only used for current-value lookups, not as reactive dependencies.

    What alternative solutions did you explore? (Optional)

    • Using startTransition from React 18 was considered but INP measures time to next paint, and startTransition still blocks the main thread — it just marks the update as non-urgent for React scheduler, which does not help with INP.
    • Moving validation to a Web Worker was considered but impractical since it needs access to React state and Onyx stores.
  9. melvin-bot commented on Mar 17, 2026

    @melvin-bot

    📣 @mendarb! 📣
    Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
    Please follow these steps:

    1. Make sure you've read and understood the contributing guidelines.
    2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
    3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  10. czarflix commented on Mar 18, 2026

    @czarflix

    I’m working on reproducing this on staging, will update shortly.

  11. melvin-bot commented on Mar 18, 2026

    @melvin-bot

    📣 @czarflix! 📣
    Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
    Please follow these steps:

    1. Make sure you've read and understood the contributing guidelines.
    2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
    3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  12. 109 remaining items

  13. rojiphil commented on Jul 23, 2026

    @rojiphil
    Contributor

    BugZero Checklist:

    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: Skipping the link as this is an improvement feature

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: Not Required. The existing checklist is good enough to capture such issues.

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Regression Test Proposal Template

    Regression Test Proposal

    Precondition:

    Test:

    Account > Profile > Display name

    1. Go to Account (bottom tab) > Profile > Display name.
    2. Change the first name and press Save.
    3. Verify the spinner appears on Save the instant it is pressed (before the value persists) and the form saves correctly.
    4. Reopen the form, clear a required field and press Save.
    5. Verify the validation error shows and the spinner does NOT stay stuck (it cancels on violations).
    6. Rapidly double-press Save on a valid form.
    7. Verify the form is submitted only once (no duplicate request).

    Account > Profile > Contact method (or Workspace > Profile > Name)

    1. Open the form, enter a valid value and press the submit button.
    2. Verify the spinner appears immediately on press and the form submits correctly (confirms the behavior is global to the Form framework).

    Group chat > Invite participant

    1. Open a group chat > tap the header > Members > Invite member.
    2. Select a member and press Invite, then immediately press Back.
    3. Verify there is no stuck spinner on Invite and the button is pressable again.

    Room > Invite member

    1. Open a workspace room > tap the header > Members > Invite member.
    2. Select a member and press Invite, then immediately press Back.
    3. Verify there is no stuck spinner on Invite and the button is pressable again.

    Expense report > Change approver > Add approver

    1. Open an expense report > Report details > Change approver > Add approver.
    2. Select an approver and press Save, then immediately press Back.
    3. Verify there is no stuck spinner on Save and the button is pressable again.

    Report > Create task

    1. Open a report > compose menu (+) > Assign task, fill in the details.
    2. Press Confirm task, then immediately press Back.
    3. Verify there is no stuck spinner on Confirm task and the button is pressable again.

    Settings > Rules (personal rule)

    1. Go to Account > Settings > Rules > create/edit a rule.
    2. Press Save rule.
    3. Verify the spinner shows immediately and clears.
    4. Workspace > Rules > Merchant rules

    Go to Workspace > Rules > Merchant rules > create/edit a rule.

    1. Press Save rule.
    2. Verify the spinner shows immediately and clears.
    3. Workspace > Rules > Spend rules > Choose cards

    Go to Workspace > Rules > Spend rules > add/edit a rule > Choose cards.

    1. Select cards and press Save/Confirm.
    2. Verify the spinner shows immediately and clears.
    3. Workspace > Rules > Spend rules (rule config)

    Go to Workspace > Rules > Spend rules > add/edit a rule.

    1. Press Save rule.
    2. Verify the spinner shows immediately and clears.
    3. Workspace > Rules > Spend rules > Spend category

    Go to Workspace > Rules > Spend rules > add/edit a rule > Spend category.

    1. Select categories and press Save.
    2. Verify the spinner shows immediately and clears.
    3. Workspace > Rules > Spend rules > Merchants

    Go to Workspace > Rules > Spend rules > add/edit a rule > Merchants.

    1. Add a merchant and press Save.
    2. Verify the spinner shows immediately on Save and clears.
    3. Workspace - Workflows

    Workspace > Workflows > Create workflow

    1. Go to Workspace > Workflows > Create workflow, configure approvers.
    2. Press Add workflow, then immediately press Back.
    3. Verify there is no stuck spinner and the button is pressable again.

    Workspace > Workflows > Edit workflow

    1. Go to Workspace > Workflows > open an existing workflow.
    2. Press Save, then immediately press Back.
    3. Verify there is no stuck spinner and the button is pressable again.

    Workspace > Workflows > Expenses from

    1. Go to Workspace > Workflows > Create workflow > "Expenses from".
    2. Select members and press Next.
    3. Verify the spinner shows immediately on press.
    4. Workspace - Members & Company cards

    Workspace > Members > Invite member

    1. Go to Account > Workspaces > select a workspace > Members > Invite member.
    2. Select a member and press Next.
    3. Verify the spinner shows immediately on press.

    Workspace > Company cards > Settings > Statement close date

    1. Go to Workspace > Company cards > Settings > Statement close date.
    2. Pick a date and press Save/Confirm, then immediately press Back.
    3. Verify there is no stuck spinner and the button is pressable again.
    4. Workspace > Company cards > Assign card > Card selection

    Go to Workspace > Company cards > Assign card > select assignee > Card selection.

    1. Select a card and press Next/Confirm, then immediately press Back.
    2. Verify there is no stuck spinner and the button is pressable again.

    Account > Domains > Admins > Invite

    1. Go to Account > Domains > select a domain > Admins > Invite.
    2. Select a user and press Invite, then immediately press Back.
    3. Verify there is no stuck spinner and the button is pressable again.

    Account > Wallet > Add bank account > Bank account purpose

    1. Go to Account > Wallet > Add bank account > Bank account purpose.
    2. Select a country and press Next, then immediately press Back.
    3. Verify there is no stuck spinner and the button is pressable again.

    Account > Wallet > Report virtual card fraud

    1. Go to Account > Wallet > open an Expensify virtual card > Report fraud.
    2. Press Deactivate card.
    3. Verify the spinner shows immediately on press and the card deactivates.

    Sign-in > Login form

    1. From the logged-out screen, enter an email and press Continue.
    2. Verify there is no stuck spinner on Continue if you return to the login form.

    Additional Card Scenarios

    Precondition:
    Workspace has at least one Expensify Card.

    Steps:

    1. Go to staging.new.expensify.com
    2. Go to workspace settings > Expensify Card.
    3. Open Expensify Card.
    4. Click Amount.
    5. Change the amount to 0 > Save.
    6. Click Cancel.
    7. Verify that the Save button do not load infinitely

    Steps:

    1. Log in as a Workspace Admin
    2. Navigate to Workspace > Expensify Card
    3. Invite the test user to the workspace if not already invited
    4. Issue a Physical Card (not a Virtual Card) to the test user
    5. Log in as the test user
    6. Navigate to Account > Wallet
    7. Select the newly issued card under Cards and click/tap "Get physical card"
    8. If prompted, enter Name, Date of Birth, and Address information
    9. Enter PIN "1111"
    10. Click/tap "Reveal PIN"
    11. Click/tap "Hide PIN"
    12. Click/tap "Next" > Verify the error message "Please choose a more secure PIN" is displayed
    13. Result: Next button starts loading infinitly
    14. Replace the PIN with "1031"
    15. Click/tap "Next"
    16. Verify that the button do not load infinitely.

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-38af-ae3b-e62b-0d1afcbe9404
  14. mallenexpensify commented on Jul 27, 2026

    @mallenexpensify
    Contributor

    @rojiphil from the C+ doc

    If there are posts on the PR or issue that reference a regression or deploy blocker, C+ posts on the issue and confirms regression (which will reduce pay by 50%) or provides reasoning why they shouldn’t be considered. If the C+ doesn’t update the issue, the contributor manager making the payment will assume any mention of a regression or deploy blockers reduces the issue amount.

    ^ Test case created. Thx

  15. rojiphil commented on Jul 27, 2026

    @rojiphil
    Contributor

    Ah yes! Agree that there were regressions here.
    @rlinoz Due to the nature of the improvement added here, there were already quite a lot of use cases covered in testing, which required more time than what we regularly take for a default compensation. So, although I agree that we missed some additional edge cases which were covered later via regression fixes, can we go ahead with the default compensation here considering the vast coverage area of test cases?

  16. rlinoz commented on Jul 27, 2026

    @rlinoz
    ContributorAuthor

    Yes, I think it is fair. We touched a lot of different paths with this change and the edge cases were minor.

  17. rojiphil commented on Jul 27, 2026

    @rojiphil
    Contributor

    Thanks @rlinoz.

    @mallenexpensify Over to you now for the payment summary here based on #85596 (comment) and #85596 (comment). Thanks.

  18. mallenexpensify commented on Jul 27, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @rojiphil due $250 via NewDot

    Thx for the detailed explanation, thanks @rlinoz for confirming

  19. nyomanjyotisa commented on Aug 28, 2026

    @nyomanjyotisa
    Member

    The implementation in #92498 introduced the stuck Save state reported in #99152. It was fixed in #99344 by opting the Travel Billing monthly-limit form out of immediate press loading.

  20. quinthar commented on Sep 2, 2026

    @quinthar
    Contributor

    Approved $250 to @rojiphil

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 productionBugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions