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

未关闭 适合新手
#7,826 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@masenf 已经在做这个了。

开始于 2026年11月11日。

  • #7800 来自 @masenf —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
frontend

调研方向

Issue 提到了 ArrayVar 及其数组操作,并以 SetVar.to_array() 中对可选集合的处理作为参考。阅读 #7800 的更改,追踪可选列表的 contains 和 length 如何编译;使用提供的示例重现故障。当 None 被渲染为空列表,使得 contains 为 false、length 为 0,且 prerender 成功时,即告完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
29k
派生
1.8k
平均合并
2 天 22 小时
30 天内合并 PR
143

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

reflex-dev/reflex 的其他 Issue

查看 reflex-dev/reflex 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。