Skip to content

Segment UI only renders first top-level rule, silently drops additional rules #7254

@adamvialpando

Description

@adamvialpando

Bug Description

When a segment is created via the Admin API with multiple top-level rules (i.e., the rules array at the segment level has 2+ entries), the dashboard UI only renders the first top-level rule. Additional rules are completely invisible in the visual editor there is no scroll and no indicator.

The API accepts and returns all rules correctly. The data is stored and the flag engine evaluates all rules. But the UI silently hides everything after rules[0].

Editing the segment in the dashboard would silently drop the hidden rules.

Steps to Reproduce

  1. Create a segment via Admin API with two top-level rule groups:

POST /api/v1/projects/{PROJECT_ID}/segments/

With two entries in the top level rules array, each with type ALL and containing sub-rules scoped to different environments via $.environment.name.

  1. Verify the API response contains both top level rules
  2. Open the segment in the Flagsmith dashboard

Expected Behavior

The UI should display both top level rule groups, or at minimum indicate that additional rules exist.

Actual Behavior

Only the first top level rule group is rendered. The second is completely missing from the editor.

Root Cause

The frontend hard codes rules[0] throughout CreateSegment.tsx:

  • addRule() (line ~214): appends to rules[0].rules
  • updateRule() (line ~224): modifies rules[0].rules[elementNumber]
  • Rendering (line ~338): maps over rules[0].rules only
  • Validation: checks only rules[0].rules

The UI assumes a single top level ALL wrapper rule. The API and backend have no constraint. The serializer uses many=True and the DB model supports multiple top level rules via FK.

Impact

  • Users creating segments via API with multiple top-level rules see incomplete data in the UI
  • Editing such a segment in the dashboard silently drops hidden rules (data loss)
  • Use case: customers migrating from other vendors who want one segment with per-environment targeting rules

Suggested Fix

Either:

  1. Frontend: Update the UI to iterate over all top-level rules instead of only rules[0]
  2. Backend: Add API validation to reject/warn when multiple top-level rules are submitted
  3. Both: Render them properly and decide if this is an intended feature

At minimum, the UI should warn when hidden rules exist to prevent silent data loss on edit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions