Skip to content

[HOLD #82586][$250] Expense - Amount input field loses focus #84960

Closed

Description

@vincdargento

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: v9.3.36-0
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from BrowserStack: N/A
Email or phone of affected tester (no customers): testpayment935@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Critical User Impact
Device used: Windows 11 pro /Chrome
App Component: Money Requests

Action Performed:

  1. Navigate to staging.new.expensify.com
  2. FAB > Create Expense

Expected Result:

The amount input field doesn't lose focus

Actual Result:

Amount input field loses focus so unable to enter amount unless focusing again

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

bug.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022041833377896843449
  • Upwork Job ID: 2041833377896843449
  • Last Price Increase: 2026-04-08

Activity

  1. added
    DeployBlockerCash
    Daily
    Bug
    on Mar 11, 2026
  2. melvin-bot commented on Mar 11, 2026

    @melvin-bot

    Triggered auto assignment to @rlinoz (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

  3. melvin-bot commented on Mar 11, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. github-actions commented on Mar 11, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  5. OSBotify commented on Mar 11, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #84780 - "[No QA] Revert "fix: Amount is out of view when max number of digits"" by @aimane-chnaif (High confidence)
    Related Issues: #81655 (original PR that was reverted)

    Recommendation: REVERT

    Revert PR #84780 to restore the previous behavior. While the revert was done to prevent a different bug from reaching staging, it introduced this focus loss regression.

    Labels: No changes needed. This is correctly labeled as DeployBlockerCash (frontend bug). The fix requires reverting App PR #84780.

    Detailed Analysis

    Evidence

    PR #84780 was merged on 2026-03-10 at 18:38:49Z, which is:

    • In the current staging deploy (v9.3.36-0)
    • Before the bug was reported (2026-03-11 at 20:51:34Z)
    • Not yet on production (bug is only reproducible on staging)

    The PR reverted changes to src/components/NumberWithSymbolForm.tsx that added a useMemo hook for calculating dynamic font sizes based on amount length. The revert removed:

    1. A useMemo hook that computed dynamicAmountStyle
    2. The useStyleUtils hook
    3. The getAmountInputFontSize utility function

    Verification

    The affected files are:

    • src/components/NumberWithSymbolForm.tsx - Core component for amount input
    • src/pages/iou/MoneyRequestAmountForm.tsx - Wraps NumberWithSymbolForm
    • src/pages/iou/request/step/IOURequestStepAmount.tsx - The expense creation flow page

    PR #84780 directly modifies NumberWithSymbolForm.tsx, which is the component responsible for rendering the amount input field in the expense creation flow.

    Root Cause

    When PR #81655 originally added the useMemo hook for dynamic styling, it likely introduced a different bug (shown in screenshot comment). The revert removed this memoization, but in doing so appears to have changed the component re-render behavior in a way that causes the input to lose focus.

    The issue occurs because the style object reference changes on every render without memoization, which can trigger React to unmount/remount or blur/refocus the underlying TextInput component. This is particularly problematic in web browsers where DOM manipulation tied to style changes can interfere with focus state.

  6. vincdargento commented on Mar 11, 2026

    @vincdargento
    Author

    The culprit PR must be #84448 (snapshot build not generated, so can't test on this one) or #84452

  7. MelvinBot commented on Mar 11, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When navigating to FAB > Create Expense on staging (v9.3.36-0), the amount input field loses focus immediately, requiring the user to manually tap/click the input before they can enter an amount. This does not happen on production.

    What is the root cause of that problem?

    The root cause is PR #84286 (perf: optimize ManualOpenCreateExpense with policy selector and reduced subscriptions), which changed how selectedTab is managed in IOURequestStartPage.tsx.

    Before PR #84286 (production): selectedTab was stored in React local state via useState(lastSelectedTab), with a useEffect to sync from Onyx. When OnyxTabNavigator wrote the initial tab value back to Onyx via Tab.setSelectedTab(), the useEffect in IOURequestStartPage would bail out because selectedTab was already truthy (set by the immediate setSelectedTab call in onTabSelected). This prevented the Onyx roundtrip from causing a re-render of the parent component.

    After PR #84286 (staging): selectedTab is derived directly from the Onyx value (const selectedTab = lastSelectedTab at IOURequestStartPage.tsx:88). Now when OnyxTabNavigator writes the tab to Onyx on mount (OnyxTabNavigator.tsx:190), that write propagates back through useOnyx, causing IOURequestStartPage to re-render. Since selectedTab is used in several rendering-significant props — ScreenWrapper.shouldEnableMaxHeight (line 294), DragAndDropProvider.isDisabled (line 299), the transactionRequestType memo (line 153) — this triggers a cascade of child re-renders.

    Meanwhile, IOURequestStepAmount has a useFocusEffect (IOURequestStepAmount.tsx:170-182) that schedules focus via a 400ms setTimeout. When the parent re-renders from the Onyx roundtrip during this window, the useFocusEffect cleanup fires and clears the pending focus timeout. If the component subtree re-mounts due to changed ScreenWrapper/DragAndDropProvider props, focus is permanently lost.

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

    Restore the local state buffer for selectedTab in IOURequestStartPage.tsx. Specifically, revert the selectedTab derivation back to using useState + useEffect to buffer the Onyx value, while keeping the other performance improvements from PR #84286 (the iouRequestPolicyCollectionSelector and the NVP selector for SCAN_TEST_TOOLTIP). The key change needed:

    1. In IOURequestStartPage.tsx, replace const selectedTab = lastSelectedTab with a useState/useEffect pair that initializes from and syncs with lastSelectedTab, and restore setSelectedTab(newIouType) in the onTabSelected callback. This prevents the Onyx roundtrip from Tab.setSelectedTab() from triggering a re-render of the page during the initial mount sequence.

    What alternative solutions did you explore? (Optional)

    1. Increase the focus timeout in IOURequestStepAmount.tsx to exceed the Onyx roundtrip window. This is fragile and timing-dependent — not recommended.
    2. Use useRef instead of direct derivation for selectedTab to avoid re-renders. This would work but is more complex than restoring the proven useState pattern.
    3. Check if the entire PR perf: optimize ManualOpenCreateExpense with policy selector and reduced subscriptions #84286 should be reverted. The other changes (policy collection selector, NVP selector) are independent and don't affect focus. A targeted fix is preferable.

    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  8. rlinoz commented on Mar 12, 2026

    @rlinoz
    Contributor

    I can't repro this and the theoretically offending PR is already in prod...

  9. 22 remaining items

  10. melvin-bot commented on May 4, 2026

    @melvin-bot

    This issue has not been updated in over 15 days. @rlinoz, @ChavdaSachin eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  11. rlinoz commented on May 5, 2026

    @rlinoz
    Contributor

    Still on hold.

  12. moxw commented on Jun 5, 2026

    @moxw

    Proposal

    What is the root cause of that problem?

    The amount field is focused by a delayed effect in IOURequestStepAmount:

    • src/pages/iou/request/step/IOURequestStepAmount.tsx schedules textInput.current?.focus() after CONST.ANIMATED_TRANSITION + 100.
    • The same flow is rendered inside IOURequestStartPage for FAB > Create Expense.

    The focus is then lost because IOURequestStartPage now derives selectedTab directly from Onyx:

    const [lastSelectedTab] = useOnyx(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.IOU_REQUEST_TYPE}`);
    const selectedTab = lastSelectedTab;

    OnyxTabNavigator writes the selected tab back to the same Onyx key during its initial/tab state event via Tab.setSelectedTab(), then calls onTabSelected(). That callback runs useResetIOUType, which can call Keyboard.dismiss() and rebuild/update the draft transaction.

    So the failing chain is:

    1. FAB > Create Expense navigates through startMoneyRequest() to the create expense tab route.
    2. The Manual amount tab renders and schedules focus.
    3. OnyxTabNavigator persists the selected tab during the same mount/tab-selection window.
    4. IOURequestStartPage receives that Onyx update and re-renders layout-affecting props such as ScreenWrapper.shouldEnableMaxHeight, DragAndDropProvider.isDisabled, and transactionRequestType.
    5. useResetIOUType may also dismiss the keyboard and update the draft transaction.
    6. This lands during/after the delayed focus window, so on web/Chrome the amount input briefly focuses and then blurs.

    This is timing-sensitive, which explains why it can be intermittent and dependent on the existing persisted selected tab / draft transaction state.

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

    Restore a local selectedTab buffer in IOURequestStartPage instead of rendering directly from the Onyx value.

    Specifically:

    1. Initialize local state from lastSelectedTab.
    2. Sync from Onyx only when the local selected tab is still empty and Onyx has finished loading.
    3. In the onTabSelected callback, call setSelectedTab(newIouType) immediately before resetIOUTypeIfChanged(newIouType).

    That keeps the tab UI stable during the initial Onyx roundtrip and prevents the parent create-expense page from re-rendering after the amount input’s delayed focus has already been scheduled.

    As hardening, useResetIOUType should avoid dismissing the keyboard for no-op tab selections. The transaction?.iouRequestType === newIOUType guard should happen before Keyboard.dismiss(), because an initial tab state event that confirms the already-selected tab should not blur the active amount input.

    Verification plan:

    • On web/Chrome, clear or change the persisted selectedTab_iouRequestType, then use FAB > Create Expense and land on/open the Manual amount tab.
    • Confirm the amount input remains focused and accepts typing immediately.
    • Repeat with a previously persisted Manual tab and with a stale Scan/Distance selected tab.
    • Add a focused test around IOURequestStartPage/OnyxTabNavigator verifying that the initial selected-tab Onyx write does not cause a post-focus blur/no-op keyboard dismiss for the amount step.

    What alternative solutions did you explore? (Optional)

    Increasing the amount-step focus timeout would only hide the race and would still be vulnerable to slower Onyx updates.

    Forcing another focus from NumberWithSymbolForm or MoneyRequestAmountInput is also too narrow because the blur is caused by parent tab/Onyx state churn, not by amount formatting itself. The fix should stabilize the tab state boundary and avoid dismissing the keyboard on no-op tab initialization.

  13. rlinoz commented on Jun 8, 2026

    @rlinoz
    Contributor

    @ChavdaSachin how is that issue going?

  14. ChavdaSachin commented on Jun 11, 2026

    @ChavdaSachin
    Contributor

    This issue was resolved somewhere.
    I don't remember where, though.

    POC
    Screen.Recording.2026-06-11.at.9.40.55.PM.mov
  15. rlinoz commented on Jun 11, 2026

    @rlinoz
    Contributor

    ah thanks, closing then

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

Metadata

Metadata

Labels

BugDailyEngineeringExternalHelp Wanted

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions