Skip to content

Fix client state setter event var args - #6935

Open
wantosure wants to merge 2 commits into
reflex-dev:mainfrom
wantosure:codex/fix-client-state-event-var
Open

Fix client state setter event var args#6935
wantosure wants to merge 2 commits into
reflex-dev:mainfrom
wantosure:codex/fix-client-state-event-var

Conversation

@wantosure

@wantosure wantosure commented Aug 24, 2026

Copy link
Copy Markdown

Fixes #5741.

ClientStateVar.set_value() was using the rendered value expression to build the wrapper function argument. That works for plain event vars, but breaks for optional-chain expressions like _event?.clientX because the generated handler ends up with _event?.clientX as the argument name:

((_event?.clientX) => ...)

This patch keeps the setter call value as-is, but derives the wrapper argument from the leading event identifier instead, so the generated function is valid:

((_event) => ...(_event?.clientX))

Added a regression test for the optional-chain client-state setter case.

Tested with:

python -m pytest tests\units\test_event.py -q
python -m pytest tests\units\test_event.py::test_call_function_client_state_setter_accepts_optional_chain_var tests\units\compiler\test_memoize_plugin.py::test_client_state_setter_in_call_function_event_imports_refs -q
python -m ruff check reflex\experimental\client_state.py tests\units\test_event.py

Pytest warned that it could not write .pytest_cache in my Windows workspace, but the tests passed.

@wantosure
wantosure requested a review from a team as a code owner August 24, 2026 13:44
@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR updates client-state setters to derive valid wrapper argument names from event-derived expressions while preserving the complete setter value expression.

  • Adds Unicode-aware JavaScript identifier parsing for event arguments.
  • Adds regression coverage for optional-chain and Unicode event variables.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
reflex/experimental/client_state.py Replaces expression-based wrapper parameters with leading event-identifier extraction so optional-chain setter expressions generate valid JavaScript.
tests/units/test_event.py Adds focused serialization tests for optional-chain and Unicode client-state setter event expressions.

Reviews (2): Last reviewed commit: "Handle unicode event argument names" | Re-trigger Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread reflex/experimental/client_state.py Outdated
@wantosure

Copy link
Copy Markdown
Author

Thanks, this was a valid catch.

The old regex only handled ASCII identifier characters, so an event expression such as _événement?.clientX would bind _ as the callback arg and then reference _événement inside the body.

I replaced that with a small Unicode-aware JS identifier scanner and added a regression test for the non-ASCII event arg case.

Verified with:

  • python -m pytest tests\units\test_event.py -q
  • python -m ruff check reflex\experimental\client_state.py tests\units\test_event.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid JavaScript Code Generation with EventHandler args_spec Using rx.Var Expressions

1 participant