Skip to content

[Due for payment 2026-03-02] Rules - Category row shown in Merchant Rule after offline category deletion #82936

Closed

Description

@jponikarchuk

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.22-2
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: #82438
Email or phone of affected tester (no customers): dreamnitethedragon@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Redminote 10S Android 13
App Component: Money Requests

Action Performed:

  1. Launch app
  2. Create a workspace
  3. Enable rules
  4. Open expense rule - new rule - category
  5. Note categories are listed
  6. Open rules - add merchant rule - category
  7. Note categories are listed
  8. Open workspace chat
  9. Start creating expense and open category row in the flow
  10. Note categories are listed
  11. Go offline
  12. Go to category - settings
  13. Toggle off members must categorise expense
  14. Delete all categories
  15. Go merchant rule/ expense rule / expense creation flow and note category row

Expected Result:

In expense rule and in expense creation flow, category row is not shown similarity in merchant rule also, category row must not be shown after deleting categories in offline.

Actual Result:

In expense rule and in expense creation flow, category row is not shown but in merchant rule category row is shown after deleting categories in offline.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @lydiabarclay

Activity

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

    @melvin-bot

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

  3. melvin-bot commented on Feb 19, 2026

    @melvin-bot

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

  4. melvin-bot commented on Feb 19, 2026

    @melvin-bot

    Triggered auto assignment to @lydiabarclay (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 Feb 19, 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 Feb 19, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #82438 - "Enable merchant rules v2" by @luacmartins (High confidence)
    Related Issues: #80855

    Recommendation: REVERT

    This PR enabled merchant rules for all users by removing the production environment check. However, the merchant rules feature has a bug where it does not properly handle offline category deletions. The category row continues to be shown in the merchant rule flow even after categories are deleted offline, while the expense rule and expense creation flows correctly hide the category row.

    Labels: No changes needed - DeployBlockerCash is correctly applied as this is a frontend bug requiring an App fix.

    Detailed Analysis

    Evidence

    The issue was reported in version V9.3.22-2 and is reproducible only in staging (not production) because merchant rules v2 is a new feature that does not exist in production yet. The bug was caught during regression testing of PR #82438.

    The PR removed the production environment check that was previously hiding merchant rules:

    -    const {isProduction} = useEnvironment();
    -
    -    if (isProduction) {
    -        return null;
    -    }

    Verification

    The affected files are:

    • /home/runner/_work/App/App/src/pages/workspace/rules/MerchantRules/MerchantRulePageBase.tsx - Contains the hasCategories() function that checks if categories should be shown
    • /home/runner/_work/App/App/src/pages/workspace/rules/MerchantRulesSection.tsx - The component that was modified in PR Enable merchant rules v2 #82438

    Root Cause

    The hasCategories() function in MerchantRulePageBase.tsx (lines 135-140) does not filter out categories with pendingAction: "delete":

    const hasCategories = () => {
        if (!policy?.areCategoriesEnabled) {
            return false;
        }
        return Object.keys(policyCategories ?? {}).length > 0;
    };

    This differs from other parts of the codebase that properly handle pending delete actions:

    • The hasEnabledOptions() utility function in OptionsListUtils correctly filters: option.enabled && option.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE
    • The IOURequestStepCategory component uses hasEnabledOptions(Object.values(policyCategories ?? {})) to determine if categories should be shown
    • The getAvailableNonPersonalPolicyCategories() function in CategoryUtils.ts filters out categories with pending delete actions

    When offline:

    1. User deletes all categories (they get pendingAction: "delete")
    2. Expense rules and expense creation flows use hasEnabledOptions() which filters deleted categories, so category row is correctly hidden
    3. Merchant rules use hasCategories() which only checks Object.keys().length, so category row incorrectly remains shown

    While this bug existed before PR #82438, the PR made it visible to all users by removing the production gate.

  7. twilight2294 commented on Feb 19, 2026

    @twilight2294
    Contributor

    Proposal

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

    When all workspace categories are deleted while offline, the Category row continues to appear in the Merchant Rule page even though those categories are pending deletion. This inconsistency differs from the expense creation flow and expense rule pages, which correctly hide the category row in the same scenario.

    What is the root cause of that problem?

    The hasCategories() function in MerchantRulePageBase uses Object.keys(policyCategories ?? {}).length > 0 to determine whether categories exist. This check does not account for the offline-first optimistic update pattern used by deleteWorkspaceCategories().

    When categories are deleted offline, the optimistic update in Category sets each deleted category's pendingAction to CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE rather than immediately removing the keys from the Onyx store. The keys are only nullified upon server confirmation. As a result, Object.keys(policyCategories ?? {}).length > 0 remains true even when all categories are pending deletion, causing hasCategories() to incorrectly return true.

    By contrast, the expense creation flow (MoneyRequestConfirmationList) and expense rule page (IOURequestStepCategory) both use hasEnabledOptions() from OptionsListUtils, which explicitly filters out categories with pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE. This is why those flows behave correctly while the merchant rule page does not.

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

    In MerchantRulePageBase, replace the naive key-count check with hasEnabledOptions() from OptionsListUtils:

    // Before (line 139)
    return Object.keys(policyCategories ?? {}).length > 0;
    
    // After
    return hasEnabledOptions(policyCategories ?? {});

    This mirrors the exact pattern used in the expense creation flow and expense rule page, ensuring that categories pending deletion are excluded from the check.

    What alternative solutions did you explore? (Optional)

    An inline filter could be added directly in hasCategories() without importing hasEnabledOptions, e.g. Object.values(policyCategories ?? {}).some(c => c.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE). However, reusing the existing hasEnabledOptions utility is preferable for consistency and maintainability, since it also checks the enabled flag and is already the established pattern for this exact scenario across the codebase.

  8. 8 remaining items

  9. luacmartins commented on Feb 19, 2026

    @luacmartins
    Contributor

    I have a PR in review to fix this issue. Let's keep it open for now

  10. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Feb 23, 2026
  11. changed the title [-]Rules - Category row shown in Merchant Rule after offline category deletion[/-] [+][Due for payment 2026-03-02] Rules - Category row shown in Merchant Rule after offline category deletion[/+] on Feb 23, 2026
  12. melvin-bot commented on Feb 23, 2026

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  13. melvin-bot commented on Feb 23, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.24-3 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-03-02. 🎊

  14. melvin-bot commented on Feb 23, 2026

    @melvin-bot

    @luacmartins @lydiabarclay The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  15. lydiabarclay commented on Mar 2, 2026

    @lydiabarclay
    Contributor

    @luacmartins is payment needed on this GH?

  16. luacmartins commented on Mar 2, 2026

    @luacmartins
    Contributor

    No, good to close.

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.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions