Auto-memoization splits local client-state button text from its setter
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python, react
- Domain
- frontend, full-stack
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 29k
- Forks
- 1.8k
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 143
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from reflex-dev/reflex
-
Operations on a list[T] | None var throw when the value is NonePossibly taken @masenf claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
reflex-dev/reflex#7826 · 1 comment ·
Maintainers usually reply within 1 day
-
A dev run stopped before its backend loads leaves .web/nocompile, so the next run or export skips the compilePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
reflex-dev/reflex#7825 · 1 comment ·
Maintainers usually reply within 1 day
-
PropsBase nested serialization applies parent include/exclude filters to child fieldsPossibly taken @harsh21234i claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
reflex-dev/reflex#7787 · 1 comment ·
Maintainers usually reply within 1 day
-
OTel: add trace_flags to JSON log records so unsampled trace ids are recognizablePossibly taken @ShaanGS claimed this 7 days ago. Openenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
reflex-dev/reflex#7729 · 1 comment ·
Maintainers usually reply within 1 day
-
0.9.12 changelog follow-ups: the #7132 "_get_was_touched" entry describes unreachable behaviour, #7115's hasattr/getattr change is undocumented, #7131's wordingMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
reflex-dev/reflex#7260 · 2 comments ·
Maintainers usually reply within 1 day
All issues in reflex-dev/reflex
Similar issues
-
release
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
MichaelYcJo/SpecSeal#1535 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
valentinfrlch/ha-llmvision#769 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 75/100
daniel-ospina/tortoise#11937 · 1 comment ·
Maintainers usually reply within 1 day
-
good first issue help wanted python up-for-grabs
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
andrewsiah/agentswarm-data-tasks#238 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
cadence-workflow/cadence-ai-samples#175 ·
Maintainers usually reply within 1 day