Skip to content

Rules - Unable to save empty merchant field #84199

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: 9.3.31-0
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #83005
Email or phone of affected tester (no customers): sodijsojosjsdoj@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Workspace Settings

Action Performed:

Precondition:

  • Rules are enabled.
  1. Go to staging.new.expensify.com
  2. Go to workspace settings > Rules.
  3. Click Add merchant rule.
  4. Click Merchant field under "Apply these updates".
  5. Enter anything and save it.
  6. Click the same Merchant field.
  7. Clear the field and save it.

Expected Result:

User should be able to clear the field and save it in case they decide not to make any changes to merchant.

Actual Result:

User cannot clear Merchant field once it has been saved with value.
In order to clear it, user will need to close the RHP and restart the process.

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

Issue OwnerCurrent Issue Owner: @luacmartins

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 4, 2026
  2. melvin-bot commented on Mar 4, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #83005

  3. melvin-bot commented on Mar 4, 2026

    @melvin-bot

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

  4. melvin-bot commented on Mar 4, 2026

    @melvin-bot

    Triggered auto assignment to @dylanexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  5. github-actions commented on Mar 4, 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.
  6. OSBotify commented on Mar 4, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #81205 - "fix Expense - Merchant can be made empty by using Expense as Merchant in expense rule" by @situchan (High confidence)
    Related PRs: #83005 - "Enable merchant rules v3" (exposed the issue by removing production gate)

    Recommendation: ROLL FORWARD

    The bug exists in validation logic added by PR #81205 (merged Feb 3), but was only exposed when PR #83005 removed the production gate for merchant rules. The issue is that the validation incorrectly prevents users from clearing the merchant field once a value has been saved.

    Root Cause: The validation in src/components/Rule/TextBase.tsx calls isInvalidMerchantValue(trimmedValue) for non-required merchant fields. This function returns true for empty strings, which prevents users from clearing the field. The validation should only check for invalid values when the field is NOT empty.

    Rolling forward with a fix is more appropriate than reverting because:

    1. PR fix Expense - Merchant can be made empty by using Expense as Merchant in expense rule #81205 was merged over a month ago (Feb 3) and is not in this deploy
    2. Multiple subsequent PRs have built on this code
    3. The fix is straightforward: skip isInvalidMerchantValue check when the field is empty and not required

    Labels: No label changes needed. This is reproducible only on staging (new feature), and it is a frontend bug that requires an App PR to fix. DeployBlockerCash should remain.

    Detailed Analysis

    Evidence

    Looking at the issue reproduction steps:

    • User fills the Merchant field under "Apply these updates" with a value
    • Saves it successfully
    • Tries to clear the field and save again
    • Gets an "Invalid merchant" error

    The video shows this behavior clearly - the user cannot submit when the merchant field is cleared.

    Verification

    The affected file is /home/runner/_work/App/App/src/components/Rule/TextBase.tsx, specifically the validation function starting at line 48.

    PR #81205 added this validation code (lines 65-69):

    } else if (fieldID === CONST.EXPENSE_RULES.FIELDS.RENAME_MERCHANT || fieldID === CONST.MERCHANT_RULES.FIELDS.MERCHANT) {
        if (isInvalidMerchantValue(trimmedValue)) {
            (errors as Record<string, string>)[fieldID] = translate("iou.error.invalidMerchant");
        }
    }

    The isInvalidMerchantValue function in src/libs/ValidationUtils.ts (line 775) is defined as:

    function isInvalidMerchantValue(merchant?: string): boolean {
        return merchant === "" || merchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT || merchant === CONST.TRANSACTION.DEFAULT_MERCHANT;
    }

    Notice it returns true when merchant is an empty string "".

    Root Cause

    The merchant field in AddMerchantPage is NOT marked as required (isRequired is not passed to RuleTextBase). However, the validation logic validates empty strings as "invalid" even for optional fields.

    The correct behavior should be:

    • If the field is empty and NOT required: allow it (no error)
    • If the field is empty and IS required: show "field required" error
    • If the field has a value: validate that value

    The current code validates empty strings as "invalid merchant" instead of allowing them for optional fields. The validation should be:

    } else if (fieldID === CONST.EXPENSE_RULES.FIELDS.RENAME_MERCHANT || fieldID === CONST.MERCHANT_RULES.FIELDS.MERCHANT) {
        if (trimmedValue && isInvalidMerchantValue(trimmedValue)) {  // Only check if not empty
            (errors as Record<string, string>)[fieldID] = translate("iou.error.invalidMerchant");
        }
    }
  7. MelvinBot commented on Mar 4, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When editing a merchant rule under workspace Rules, the user enters a value in the Merchant field under "Apply these updates" and saves it. When they reopen the same field, clear the text, and try to save, the form refuses to submit. The user cannot clear a previously-saved Merchant value without discarding the entire rule.

    What is the root cause of that problem?

    The TextBase component's validate function unconditionally applies the isInvalidMerchantValue check to the MERCHANT_RULES.FIELDS.MERCHANT field (src/components/Rule/TextBase.tsx:65-68). The isInvalidMerchantValue function in src/libs/ValidationUtils.ts:775-776 treats an empty string as invalid (merchant === ''). This function was designed for expense transactions where an empty merchant is genuinely invalid, but it is reused here for an optional merchant rule field where clearing the value is a legitimate user action.

    The Merchant field under "Apply these updates" is not required — AddMerchantPage does not pass isRequired to RuleTextBase (src/pages/workspace/rules/MerchantRules/AddMerchantPage.tsx:30-38), and the field is not marked required: true in the sections array of MerchantRulePageBase. However, because the isInvalidMerchantValue check runs regardless of the isRequired flag, an empty string always triggers a validation error ("Please enter a valid merchant"), and FormProvider blocks submission.

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

    In src/components/Rule/TextBase.tsx, the isInvalidMerchantValue check on lines 65-68 should only run when trimmedValue is non-empty. When the field is optional and the user clears it to an empty string, that should be treated as a valid "no value" state rather than an invalid merchant name.

    The change is in the validate function: wrap the isInvalidMerchantValue(trimmedValue) call so it only fires when trimmedValue !== ''. This way, typing something like the internal partial-transaction placeholder would still be caught as invalid, but deliberately clearing the field would be allowed.

    What alternative solutions did you explore? (Optional)

    An alternative would be to modify isInvalidMerchantValue itself to not treat empty strings as invalid, but that function is shared across the codebase for expense transaction validation where empty merchant truly is invalid. Changing it globally could break other callsites. The fix is better scoped at the TextBase validation level where the optional vs. required distinction is known.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.

  8. situchan commented on Mar 4, 2026

    @situchan
    Contributor

    @MelvinBot implement this

  9. vincdargento commented on Mar 4, 2026

    @vincdargento
    Author

    This issue is repro on all PRs in the current deployment checklist. Could you please double check if it's not introduced by #83005?

  10. situchan commented on Mar 4, 2026

    @situchan
    Contributor

    The root cause exists in production. The fix should be quick

  11. MelvinBot commented on Mar 4, 2026

    @MelvinBot
    Contributor

    🤖 Draft PR created: #84209
    Please mark it as "Ready for review" when it is ready for review.

  12. luacmartins commented on Mar 5, 2026

    @luacmartins
    Contributor

    PR merged. Being CPEd

  13. luacmartins commented on Mar 5, 2026

    @luacmartins
    Contributor

    PR CPed, this is fixed. Closing.

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.EngineeringHourlyKSv2ReviewingHas a PR in review

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions