Auto-memoization splits local client-state button text from its setter
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python, react
- 领域
- frontend, full-stack
调研方向
The issue is in the auto-memoization logic for local client state. Start by examining how rx._x.client_state generates React hooks and how child components are memoized. Look at the generated JavaScript to see the separate useState calls. The fix likely involves keeping the state reader and setter in the same React component scope. Test by running the provided reproduction script and checking the DOM updates.
由索引模型根据 Issue 内容生成。
描述
Automatic memoization separates a local client state's reader and setter into different React state instances. A button that renders its own client-state value does not visibly update when clicked.
Reproduced on main commit 31d57490470228c08595e73bcae1f86703880e26 and on 565dd92bfbb26c86d064e7bebfaf47321414c7a0.
import reflex as rx
count = rx._x.client_state("local_count", default=0, global_ref=False)
def index():
return rx.el.button(
count.value,
on_click=count.set_value(count.value + 1),
id="counter",
)
app = rx.App()
app.add_page(index)
Run the app, wait for hydration, and click the button. It keeps displaying 0; no browser error is reported. The expected text is 1, then 2 on the next click.
The generated Button memo has useState(0) and calls its own setter. Its text is rendered by a separate Bare memo with another useState(0). The setter therefore never updates the state that the text reads.
For comparison, rendering the value as an element prop keeps it in the same memo as the event handler and works:
rx.el.input(
type="button",
value=count.value,
on_click=count.set_value(count.value + 1),
)
Validated both cases through real clicks and DOM assertions in Chrome. Please keep a local client-state read and its setter in the same hook scope when memoizing children.
- 主要语言
- Python
- 星标
- 29k
- 派生
- 1.8k
- 平均合并
- 2 天 22 小时
- 30 天内合并 PR
- 143
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
reflex-dev/reflex 的其他 Issue
-
Operations on a list[T] | None var throw when the value is None可能已有人在做 @masenf 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
reflex-dev/reflex#7826 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
reflex-dev/reflex#7825 · 1 条评论 ·
维护者通常 1 天内回复
-
PropsBase nested serialization applies parent include/exclude filters to child fields可能已有人在做 @harsh21234i 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
reflex-dev/reflex#7787 · 1 条评论 ·
维护者通常 1 天内回复
-
OTel: add trace_flags to JSON log records so unsampled trace ids are recognizable可能已有人在做 @ShaanGS 于 7 天前认领。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 82/100
reflex-dev/reflex#7729 · 1 条评论 ·
维护者通常 1 天内回复
-
0.9.12 changelog follow-ups: the #7132 "_get_was_touched" entry describes unreachable behaviour, #7115's hasattr/getattr change is undocumented, #7131's wording可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
reflex-dev/reflex#7260 · 2 条评论 ·
维护者通常 1 天内回复
查看 reflex-dev/reflex 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
UKGovernmentBEIS/inspect_ai#6512 ·
维护者通常 1 天内回复
-
area/c++ area/core kind/bug-report
难度 2/5 1-3 小时 新手友好度 78/100
tensorflow/quantum#1140 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 68/100
Kav-K/GPTDiscord#501 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
UKGovernmentBEIS/inspect_evals#2863 · 1 条评论 ·
维护者通常 1 天内回复