Skip to content

Fix: TypeError when editing multivariate feature flags - missing null check on originalFlag.multivariate_options #6552

@talissoncosta

Description

@talissoncosta

Summary

Users encounter a crash when editing multivariate (MV) feature flags. The error TypeError: Cannot read properties of undefined (reading 'multivariate_options') occurs when originalFlag exists in the store but lacks the multivariate_options property.

Sentry Issue

Root Cause

In frontend/common/stores/feature-list-store.ts, the editFeatureMv function assumes originalFlag.multivariate_options always exists:

// Line 223 - crashes if originalFlag.multivariate_options is undefined
const originalMV = v.id
  ? originalFlag.multivariate_options.find((m) => m.id === v.id)
  : null

// Line 246 - also crashes
const deletedMv = originalFlag.multivariate_options.filter(
  (v) => !flag.multivariate_options.find((x) => v.id === x.id),
)

Git history:

  • Bug introduced in 4aee3b3f4 (May 30, 2022) - PR Chores/remove mv segment flag #1164
  • Partial fix attempted in 9aa67c390 (June 9, 2022) but null checks were not added
  • Likely became more frequent after RTK Query migration in 2025

Proposed Fix

Add defensive null checks:

// Line 221-224
Promise.all(
  (flag.multivariate_options || []).map((v, i) => {
    const originalMV = v.id && originalFlag?.multivariate_options
      ? originalFlag.multivariate_options.find((m) => m.id === v.id)
      : null
    // ...
  }),
)

// Line 246
const deletedMv = (originalFlag?.multivariate_options || []).filter(
  (v) => !flag.multivariate_options.find((x) => v.id === x.id),
)

Acceptance Criteria

  • Add null checks for originalFlag.multivariate_options in feature-list-store.ts
  • Editing MV feature flags no longer crashes when store data is incomplete
  • E2E tests pass

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfront-endIssue related to the React Front End Dashboard

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions