Skip to content

Operations on a list[T] | None var throw when the value is None #7826

Closed

Description

@FarhanAliRaza

Operations on a list[T] | None var that holds None throw on the frontend. #7800 fixes the same defect for set[T] | None (SetVar). Optional lists still have it.

Repro

import reflex as rx


class State(rx.State):
    items: rx.Field[list[str] | None] = rx.field(None)


def index():
    return rx.vstack(
        rx.text(State.items.contains("x")),
        rx.text(State.items.length()),
    )


app = rx.App()
app.add_page(index)

Result

The page does not render:

TypeError: Cannot read properties of null (reading 'includes')

length() fails the same way (null.length). The prod prerender fails for the same reason.

Expected

A None list acts as an empty list: contains is false and length is 0. This is the rule that #7800 uses for optional sets.

Suggested fix

Give an optional ArrayVar the same null-safe view that #7800 adds to SetVar.to_array(), which compiles to (x ?? []). Use that view in the array operations.

Activity

  1. linear-code commented on Nov 11, 2026

    @linear-code
  2. added a commit that references this issue on Nov 11, 2026
    c9f48bb
  3. added a commit that references this issue on Nov 11, 2026
    81de29f
  4. added a commit that references this issue on Nov 11, 2026
    384b63f
  5. added
    release-train
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    release-train

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions