Skip to content

[$175] [Sentry: APP-P9K] TypeError: Cannot read property 'at' of undefined in hasEnabledListValue #107169

Open

Description

@melvin-bot

Summary

Opening the Report screen can trigger an unhandled, fatal exception while rendering report fields.

  • Sentry: https://expensify.sentry.io/issues/APP-P9K
  • Impact: 2 users, 5 events at investigation time
  • First seen: 2026-11-16 21:37 UTC
  • Platform: iOS HybridApp
  • Release: new.expensify@9.5.36
  • Route: Report screen (money request report view)

Top first-party frames

src/libs/ReportUtils.ts:15482
  hasEnabledListValue / shouldHideSingleReportField
  reportField.disabledOptions.at(index)

MoneyRequestViewReportFields.tsx:150
  .filter((reportField) => !shouldHideSingleReportField(reportField))

Root cause

hasEnabledListValue iterates over reportField.values and unconditionally accesses reportField.disabledOptions.at(index). When values contains entries but disabledOptions is undefined, this throws during rendering.

The error indicates a missing array, not an unsupported .at() method. Field merging does not normalize this property. The exact origin of the affected field remains unconfirmed.

Relevant code

Suggested fix

Handle an absent disabledOptions array safely, preserving the intended behavior that missing disabled flags mean enabled.

Add regression tests covering missing, empty, partially populated, and fully disabled arrays. Verify that report rendering no longer throws.

Related issues

App#103935 and App#102788 concern report-field visibility, not this crash.

Investigation

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @aimane-chnaif

Activity

  1. added theissue type on Nov 17, 2026
  2. self-assigned this
    on Nov 17, 2026
  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 17, 2026
  4. expensify-chore-bot commented on Nov 17, 2026

    @expensify-chore-bot

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

  5. changed the title [-][Sentry: APP-P9K] TypeError: Cannot read property 'at' of undefined in hasEnabledListValue[/-] [+][$175] [Sentry: APP-P9K] TypeError: Cannot read property 'at' of undefined in hasEnabledListValue[/+] on Nov 17, 2026
  6. expensify-chore-bot commented on Nov 17, 2026

    @expensify-chore-bot
  7. moved this from CRITICAL to SUBISSUE in [#whatsnext] #qualityon Nov 17, 2026
  8. mountiny commented on Nov 17, 2026

    @mountiny
    Contributor

    @MelvinBot can you propose fix?

  9. MelvinBot commented on Nov 17, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    A list report field with populated values but missing disabledOptions crashes the visibility check because it calls .at() on the missing array.

    A helper-only fix is insufficient: editable fields subsequently perform the same unsafe access while building their dropdown options.

    Code evidence and confidence

    Confidence: medium. The code explains the reported exception, but production payloads and exact release-source mapping were not independently verified. Sentry/log access was unavailable; the origin of the missing array remains unknown. No runtime reproduction or tests were run.

    An empty flags array is already safe. Missing values would instead fail at .some(), so that does not explain the supplied error.

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

    Use !disabledOptions?.at(index) when checking each value’s disabled flag. This preserves existing semantics: absent flags mean enabled; explicitly disabled values remain excluded.

    Apply this consistently to the visibility helper, inline dropdown, dynamic editor, and initial-value picker so the fix does not simply move the crash downstream.

    Additional locations and regression coverage

    Additional unsafe readers:

    Extend existing visibility tests to cover missing, empty, shorter, mixed, and fully disabled flag arrays, plus empty values.

    Extend report-field rendering tests to verify a field with omitted flags renders, opens, and accepts a selection. Helper tests alone would miss the second crash.

    What alternative solutions did you explore? (Optional)

    Hiding fields whenever flags are missing would prevent the exception but incorrectly hide enabled choices. Reusing old report flags while adopting policy values risks misaligning positional flags.

    Related issue: Disabled list field appears after deletion concerns the same visibility area but reports different behavior; it is not a confirmed duplicate.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/107169) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  10. MelvinBot commented on Nov 17, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    The report-field visibility check assumes disabledOptions always exists. When a list has values but no disabled-flags array, accessing .at(index) throws during rendering.

    An editable dropdown repeats the same access, so fixing only the visibility check would move the crash downstream.

    Supporting code

    The code supports this mechanism; the production origin of the missing array remains unconfirmed.

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

    Use !reportField.disabledOptions?.at(index) in both checks. Continue iterating over values: missing flags should mean enabled, while explicit true flags should disable their corresponding options.

    Apply the same guard to the other dropdown readers for consistent handling.

    Other readers and regression tests

    Other readers:

    Extend visibility tests for missing, empty, shorter, mixed, and fully disabled arrays, plus empty values.

    Extend rendering tests to verify a dropdown with omitted flags renders and accepts a selection. These are proposed tests, not executed results.

    What alternative solutions did you explore? (Optional)

    Hiding fields when flags are absent would avoid the exception but incorrectly hide enabled options.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/107169#issuecomment-6961572298) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  11. fitzyracing1 commented on Nov 17, 2026

    @fitzyracing1

    Proposal

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

    Opening a money request report crashes with TypeError: Cannot read property 'at' of undefined in hasEnabledListValue (Sentry APP-P9K).

    What is the root cause of that problem?

    hasEnabledListValue in src/libs/ReportUtils.ts assumes disabledOptions is always an array:

    function hasEnabledListValue(reportField: PolicyReportField): boolean {
        return reportField.values.some((_, index) => !reportField.disabledOptions.at(index));
    }

    It's called from shouldHideSingleReportField, which MoneyRequestViewReportFields.tsx runs while rendering. The PolicyReportField type declares disabledOptions: boolean[] as required, but the data doesn't always include it. The comment right above the function already notes that fields created outside NewDot can come with an empty disabledOptions array. The crash shows they can also come with none at all.

    Also, when merging report fields, getAvailableReportFields copies disabledOptions: policyReportField.disabledOptions onto the report's field. So an undefined value on the policy field overwrites whatever the report field had.

    The same unguarded .disabledOptions.at(index) appears in two more places that would crash next, once the user opens that field:

    • src/components/MoneyRequestReportView/ReportFieldInlineInput.tsx (enabledOptions filter)
    • src/pages/DynamicEditReportFieldPage.tsx (fieldOptions filter)

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

    • In hasEnabledListValue, use reportField.disabledOptions?.at(index), so a missing array means every value is enabled. That matches the behavior the existing comment describes for empty arrays.
    • Apply the same ?. guard in ReportFieldInlineInput.tsx and DynamicEditReportFieldPage.tsx.
    • Change disabledOptions to optional (disabledOptions?: boolean[]) on PolicyReportField in src/types/onyx/Policy.ts, and on the report field type in ReportNameValuePairs.ts. TypeScript will then flag any other unguarded access. The write paths in actions/Policy/ReportField.ts that call .push/.splice should default to [] first.

    What specific scenarios should we cover in automated tests?

    Unit tests for shouldHideSingleReportField / hasEnabledListValue with a list field where disabledOptions is:

    • undefined → not hidden, no throw
    • [] → not hidden
    • partially filled (e.g. [true] with 2 values) → not hidden
    • all true → hidden

    Plus a render test that MoneyRequestViewReportFields doesn't throw for a list field without disabledOptions.

    What alternative solutions did you explore?

    Normalize the field once, in the report-field merge in getAvailableReportFields (disabledOptions: policyReportField.disabledOptions ?? field.disabledOptions ?? []). That covers the report view, but not fields read directly from the policy or from reportNameValuePairs, so I'd still add the guards above.

  12. aimane-chnaif commented on Nov 17, 2026

    @aimane-chnaif
    Contributor

    @MelvinBot implement this

  13. MelvinBot commented on Nov 17, 2026

    @MelvinBot
    Contributor

    🤖 Web test steps verification results: ❌ fail

    Web verification blocked by unavailable test data, not an observed App regression. The account has no reports, and supported tools cannot inject the required omitted-disabledOptions fixture.

    Reports screen showing No reports yet

    Step Status
    Report renders with missing disabled flagsBlocked: account has no reports.
    Reports screen showing No reports yet
    ❌
    Dropdown opens and accepts selectionNot exercised: required fixture unavailable.
    ❌
    Disabled options remain excludedNot exercised in the browser.
    ❌

    Implemented in Prevent report field crashes when disabled options are missing, a draft assigned to aimane-chnaif.

    Both targeted suites passed: 1,760 tests. Lint, typecheck, spelling, and Storybook smoke checks passed. Full-suite timeout and compiler/formatting-command limitations are documented in the PR.


    view run · no recording available

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.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions