Skip to content

fix: capture client-state setter expressions in event scope - #7692

Draft
DevChiniwala wants to merge 1 commit into
reflex-dev:mainfrom
DevChiniwala:fix/client-state-event-expression
Draft

DevChiniwala wants to merge 1 commit into
reflex-dev:mainfrom
DevChiniwala:fix/client-state-event-expression

Conversation

@DevChiniwala

@DevChiniwala DevChiniwala commented Oct 28, 2026 •

Copy link
Copy Markdown

Fixes #5741.

ClientStateVar.set_value() derives a JavaScript parameter name from its value. A custom event argument such as _event?.clientX therefore produces invalid JavaScript; other property expressions can shadow the enclosing event and read the wrong value.

Capture an explicit value in a zero-argument closure instead. The enclosing event callback supplies its scope, and .set without an explicit value keeps accepting the trigger's argument. Setter imports and initialization hooks are retained.

Validation on main at 6c3713012522:

  • 18 generated-callback execution cases: 14 fail on unchanged source and four controls pass; all pass after the fix. Covers optional chaining, dot/bracket access, nested fields and arithmetic through direct callbacks, call_function and run_script.
  • All 164 affected unit tests pass on Linux; the same tests also passed on Windows before the base refresh.
  • All 14 browser cases pass across development and production, including raw/typed event arguments, direct .set bindings and the existing shared-state behavior.
  • All nine full pre-commit hooks pass, including Pyright, ty, lint, formatting and code generation.

Full Linux suite: 15,281 passed, 64 skipped, two backend-reload failures. The backend-refusal/recovery test also fails on a clean worktree at the same base. The reload-hold test fails in the full suite but passes in both unchanged and patched isolated controls. The changed client-state tests pass in the full suite. These backend tests and implementation are unchanged by this PR; related readiness work is already open in #7416.

Keeping this draft pending backend-gate guidance and approval of the fork workflows. No complete upstream or local full-suite pass is claimed.

All submissions

  • Followed CONTRIBUTING.md and checked for an existing open PR for this fix.
  • Bug fix with an explanation, regression coverage, locally run tests and a news fragment.

View guided diff

Do not turn a value expression into a JavaScript function parameter.
Optional chaining and property access are not identifiers, and shadowing
the enclosing event can also read the wrong value. Bind explicit values
in a zero-argument closure while leaving the no-value setter unchanged.

Execute 18 generated callback cases, including 14 failing regressions on
unchanged source. Cover raw and typed event arguments and direct setter
bindings in the existing browser app in development and production.
All 164 affected tests, 14 browser cases and nine presubmit hooks pass
on the refreshed main branch. The full unit suite remains in progress.

Fixes reflex-dev#5741.
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

ClientStateVar.set_value() now captures explicit values in a zero-argument closure instead of turning their JavaScript into parameter names.

  • Client-state setters evaluate event expressions in the callback’s scope.

No actionable issues were found. Tests were inspected, not run during this review.

Reviews (1) · Last reviewed commit: "fix: capture client-state setter express..." · Reviewed by Greptile

@DevChiniwala

Copy link
Copy Markdown
Author

Final validation for 141e21ba3d2c on base 6c3713012522:

  • All 164 affected unit tests, 14 development/production browser cases and nine full presubmit hooks pass.
  • The full Linux suite has 15,281 passes, 64 skips and two Granian backend-reload failures. The refusal/recovery case also fails on unchanged main; the reload-hold case passes in both unchanged and patched isolated runs despite failing in the full suite. The backend implementation and tests are untouched.
  • Greptile reviewed this head with no actionable findings. The upstream fork workflows report action_required.

The PR description includes these limits, and this remains a draft. Could a maintainer approve the fork workflows and advise on the backend-reload gate? Related readiness work is already tracked in #7416.

This branch has not been deployed

No deployments
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