App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-12-08] [$175] [Sentry: APP-PCJ] Object.values requires that input parameter not be null or undefined in MoneyRequestView hasEnabledOptions

Open mountiny opened this issue 1 week ago • 16 comments

Sentry

https://expensify.sentry.io/issues/APP-PCJ

Impact

  • 1 user, 2 events.
  • First seen: 2026-11-18 21:59 UTC.
  • Unhandled fatal React render error; app_blocking: true.
  • Route: /search (Search_Root, transaction preview / MoneyRequestView).

Platform and release

Top first-party frames

src/libs/OptionsListUtils/index.ts:929 — hasEnabledOptions
  Object.values(options).some(isOptionEnabled)

MoneyRequestView.tsx:1213 — tagList
  canEditTag && hasEnabledOptions(tags)

MoneyRequestView.tsx:1211 — ReportActionItem_MoneyRequestView
  policyTagLists.map(({name, orderWeight, tags}, index) => ...)

Root cause

MoneyRequestView passes tags directly to hasEnabledOptions(), which calls Object.values() without a null guard.

PolicyUtils explicitly documents that empty tag lists can arrive without the tags key. getTagLists() preserves these records, and other tag utilities already tolerate missing tags.

For an editable expense with no displayed tag and nondependent tags, the render expression passes the missing value into Object.values(), causing the crash. The precise user action that produced the empty list has not been confirmed.

Suggested fix

Normalize missing tags with hasEnabledOptions(tags ?? {}), or make the shared helper explicitly accept and handle nullish inputs after reviewing its callers.

Add regression coverage for rendering an editable expense with an empty tag-list record lacking tags. The preview should render without crashing and omit the empty tag row.

Existing issues

Searches in Expensify/App and Expensify/Expensify for APP-PCJ, the exact error text, and related function/crash terms found no matching tracking issue.

Investigation

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @jayeshmangwani

mountiny avatar Nov 19 '26 23:11 mountiny

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

Job added to Upwork: https://www.upwork.com/jobs/~022123555416011104711

Proposal

What is the root cause of that problem?

An empty policy tag list can legitimately omit tags, but hasEnabledOptions() assumes its input is always present and calls Object.values() without checking.

In MoneyRequestView, this throws when the expense is editable, the affected tag level has no displayed value, and the lists are nondependent. Tag rows are computed before the visibility check, so hiding the empty tag section does not prevent the crash.

Confidence: Medium. The code explains the reported stack, but the affected user’s policy data and exact release source were not independently verified. No browser reproduction was performed.

Supporting code evidence

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

Make hasEnabledOptions() explicitly accept undefined and null and return false for either. Preserve its existing handling of enabled, disabled, and pending-deletion options.

This addresses the reported crash and the same unsafe-input pattern in other tag callers without changing list ordering or visibility rules.

Scope and regression coverage

Other direct callers include TagsOptionsListUtils.ts:261–279 and ExpenseDefaultRulePageBase.tsx:279–285.

Add regression coverage for:

  • Nullish and empty helper inputs returning false, while existing option semantics remain unchanged.
  • An editable, untagged expense with a policy list genuinely omitting tags: the preview renders and omits the empty row.
  • Independent multilevel lists with one empty list and one enabled sibling: only the appropriate row appears.

Existing render-test setup: MoneyRequestViewTest.tsx:341–389.

What alternative solutions did you explore?

A caller-only tags ?? {} fallback fixes this stack but leaves other callers exposed. Filtering empty lists out globally is inappropriate because it could change tag-level indices and discard list metadata.


Next Steps for Contributor+ team: To accept: @MelvinBot implement this to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Nov 19 '26 23:11 MelvinBot

Proposal

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

When viewing an expense in MoneyRequestView where a policy has a tag list that omits tags (an empty tag list), the application crashes with a fatal runtime error: TypeError: Object.values requires that input parameter not be null or undefined inside hasEnabledOptions.

What is the root cause of that problem?

In src/components/ReportActionItem/MoneyRequestView.tsx:1213-1215:

const tagList = policyTagLists.map(({name, orderWeight, tags}, index) => {
    const tagForDisplay = getTagForDisplay(updatedTransaction ?? transaction, shouldShowFullTransactionTag ? undefined : index);
    const shouldShow = hasDependentTags ? !!shouldShowTagList.at(index) : !!tagForDisplay || (canEditTag && hasEnabledOptions(tags));

When an empty tag list is returned from PolicyUtils/tag.ts, the list object legitimately omits the tags property (i.e. tags === undefined). When canEditTag is true and the transaction currently has no tag set (!tagForDisplay), hasEnabledOptions(tags) is called with undefined.

In src/libs/OptionsListUtils/index.ts:940-942:

function hasEnabledOptions(options: PolicyCategories | PolicyTag[]): boolean {
    return Object.values(options).some(isOptionEnabled);
}

hasEnabledOptions() does not have a null/undefined guard and immediately calls Object.values(options). In JavaScript, Object.values(undefined) and Object.values(null) throw a fatal TypeError, crashing the view and triggering Sentry event APP-PCJ.

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

Update hasEnabledOptions() in src/libs/OptionsListUtils/index.ts to accept optional/nullish options and safely return false:

/**
 * Verifies that there is at least one enabled option
 */
function hasEnabledOptions(options?: PolicyCategories | PolicyTag[] | null): boolean {
    if (!options) {
        return false;
    }
    return Object.values(options).some(isOptionEnabled);
}

This guarantees:

  1. If tags is undefined or null, hasEnabledOptions(tags) returns false cleanly.
  2. In MoneyRequestView.tsx, shouldShow evaluates to false, gracefully hiding the empty tag row without crashing.
  3. All other callers across the codebase (e.g. TagsOptionsListUtils.ts, ExpenseDefaultRulePageBase.tsx) are globally protected against nullish inputs without needing repetitive ?? {} null-coalescing guards at each call site.

Additionally, add regression tests in tests/unit/OptionsListUtilsTest.ts:

it('returns false when options is null, undefined, or empty', () => {
    expect(hasEnabledOptions(undefined)).toBe(false);
    expect(hasEnabledOptions(null)).toBe(false);
    expect(hasEnabledOptions({})).toBe(false);
    expect(hasEnabledOptions([])).toBe(false);
});

What alternative solutions did you explore?

  1. Fallback in MoneyRequestView.tsx (hasEnabledOptions(tags ?? {})): While this prevents the crash in MoneyRequestView, it leaves the other 16 call sites across the application vulnerable to identical nullish crashes. Handling it inside hasEnabledOptions() fixes the issue at its root.
  2. Filtering empty lists in getTagLists(): Not recommended because removing empty tag lists could mutate order weights, order indices, and dependent tag level alignment.

zainrizvi0611-cmd avatar Nov 20 '26 11:11 zainrizvi0611-cmd

Proposal

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

Opening an expense in Search can crash the app with "Object.values requires that input parameter not be null or undefined", thrown from hasEnabledOptions while MoneyRequestView builds its tag rows.

What is the root cause of that problem?

MoneyRequestView calls hasEnabledOptions(tags) for every tag list, and hasEnabledOptions calls Object.values(options) with no guard. An empty tag list arrives from the server without the tags key (hasDependentTags in src/libs/PolicyUtils/tag.ts already notes this), so tags is undefined and Object.values throws.

There is a second way to get a tag list with no tags: renamePolicyTagList merges {[newName]: {pendingAction: null}} on success. If the list was renamed again before that request finished, the merge recreates the old name as {pendingAction: null}, a record with no name, orderWeight or tags. getTagLists only filters null, so this leftover also reaches MoneyRequestView.

I couldn't reproduce the crash in the app: the issue has no repro steps, and the user action that produced the list isn't known. This is traced from the Sentry stack and the code.

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

  1. Make hasEnabledOptions accept undefined and null and return false for them, so real empty tag lists stop crashing every caller.
  2. In getTagLists, also drop leftover records that have no name: .filter((tagList) => !!tagList && !!tagList.name). Real tag lists, empty ones included, always have a name, so tag-level indices are unchanged. This stops the rename leftover from showing up as a blank, unsortable tag row in MoneyRequestView and in the other getTagLists callers. setPolicyTagsRequired already filters on !!tagList.name for the same reason.
  3. Unit tests: hasEnabledOptions(undefined) and hasEnabledOptions(null) return false; getTagLists keeps an empty named list and drops a {pendingAction: null} record.

What alternative solutions did you explore?

Filtering on tags in getTagLists. That would drop real empty tag lists and shift the tag-level index that getTagForDisplay uses, so it is not safe.

okie07 avatar Nov 20 '26 15:11 okie07

📣 @okie07! 📣 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>

melvin-bot[bot] avatar Nov 20 '26 15:11 melvin-bot[bot]

@jayeshmangwani can you move this ahead please?

mountiny avatar Nov 21 '26 02:11 mountiny

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01e1a10b20c43f3060

okie07 avatar Nov 21 '26 15:11 okie07

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 21 '26 15:11 melvin-bot[bot]

Proposal

Updated

okie07 avatar Nov 21 '26 15:11 okie07

Draft PR opened: https://github.com/Expensify/App/pull/107663

Root-cause fix: hasEnabledOptions() (src/libs/OptionsListUtils/index.ts) now accepts nullish options and returns false instead of calling Object.values() on them, which fixes the APP-PCJ crash for all callers (incl. MoneyRequestView). Also guarded the same pattern in getEnabledTags() (src/libs/TagsOptionsListUtils.ts). Added regression unit tests (null/undefined/{}/[]/disabled/pending-deletion) and MoneyRequestView render tests for an editable expense with an empty tag list lacking the tags key — verified they fail before the fix at the exact stack frame (index.ts:941) and pass after.

DeviousCardi avatar Nov 21 '26 17:11 DeviousCardi

📣 @DeviousCardi! 📣 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>

melvin-bot[bot] avatar Nov 21 '26 17:11 melvin-bot[bot]

Hi @jayeshmangwani, gentle Monday morning bump on this! Ready to take this forward — my proposal addresses the exact root cause with regression unit tests for hasEnabledOptions, contributor details are verified and on file, and the branch is ready to open a clean PR immediately once assigned.

zainrizvi0611-cmd avatar Nov 23 '26 00:11 zainrizvi0611-cmd

@MelvinBot implement https://github.com/Expensify/App/issues/107487

jayeshmangwani avatar Nov 23 '26 05:11 jayeshmangwani

🤖 Web test steps verification results: ❌ fail

Web verification was blocked by a blank development-app page. The required missing-tags fixture could not be created or confirmed. Blank app page blocking verification

Step Status
Preview renders without the empty tag rowBlocked: Search was inaccessible.
Blank app page blocking verification
❌
Enabled sibling tag row remains editableBlocked: the required fixture could not be established.
❌
No related JavaScript console errorsNot verified; supported console inspection was unavailable.
❌

Implemented in Prevent expense preview crash on missing tag collections, a draft assigned to jayeshmangwani.

Automated validation: 478 relevant tests passed, including regressions that reproduced the crash before the fix. Lint, typecheck, spelling, formatting, and Storybook smoke checks passed. The full suite timed out after 10 minutes; the legacy Prettier command is unavailable in this checkout.


view run · no recording available

MelvinBot avatar Nov 23 '26 06:11 MelvinBot

Hi @jayeshmangwani, seeing that MelvinBot failed the web test verification fixture and draft PR #107694 reached its step limit — just a gentle reminder that my proposal and verified fix (with unit tests covering the hasEnabledOptions guard) are ready to open as a clean contributor PR whenever you'd like to assign!

zainrizvi0611-cmd avatar Nov 23 '26 23:11 zainrizvi0611-cmd

@jayeshmangwani

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

  • https://github.com/Expensify/App/pull/107694

If no regressions arise, payment will be issued on 2026-12-08. :confetti_ball:

The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the Contributor+ 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]. If no checklist is needed for this issue, you can click: [no checklist button]

melvin-bot[bot] avatar Dec 01 '26 03:12 melvin-bot[bot]