Skip to content

fix: validate client state JavaScript identifiers - #7595

Open
harsh21234i wants to merge 2 commits into
reflex-dev:mainfrom
harsh21234i:fix/6828-client-state-js-identifiers
Open

harsh21234i wants to merge 2 commits into
reflex-dev:mainfrom
harsh21234i:fix/6828-client-state-js-identifiers

Conversation

@harsh21234i

@harsh21234i harsh21234i commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

ClientStateVar names are used as JavaScript bindings, so invalid identifiers or names that conflict with reserved words and generated Reflex bindings can produce broken frontend code.

Validate names when creating a ClientStateVar, and add tests covering rejected names and valid identifiers.

Fixes #6828.

Tests: 27 targeted tests passed; isolated Ruff check passed.

View guided diff

@harsh21234i
harsh21234i requested a review from a team as a code owner October 18, 2026 13:57

@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 3 files

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

View guided diff | Re-trigger cubic

Comment thread reflex/experimental/client_state.py Outdated
@greptile-apps

greptile-apps Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with a remaining non-blocking limit on accepted Unicode names.

Findings

  1. P2 Valid Unicode names are rejected ▶

Summary

Adds checks for ClientStateVar names before generating JavaScript.

  • Client state names now need valid JavaScript bindings.

Reviews (2) · Last reviewed commit: "fix: cover client state identifier edge ..." · Reviewed by Greptile

Comment thread reflex/experimental/client_state.py Outdated
Comment thread reflex/experimental/client_state.py Outdated
Whether the name is a valid binding that does not conflict with generated code.
"""
return (
var_name.replace("$", "_").isidentifier()

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.

P2 Valid Unicode names are rejected

Python's isidentifier() rejects some valid JavaScript names. For example, "value\u200cname" contains a zero-width non-joiner, which JavaScript permits after the first character but Python rejects. This now raises ValueError for a name that previously produced valid JavaScript. Use JavaScript's identifier rules and cover these Unicode differences in the tests.

@codspeed

codspeed Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 16 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 148 untouched benchmarks


Comparing harsh21234i:fix/6828-client-state-js-identifiers (f591cc4) with main (5ae5dcd)

Open in CodSpeed

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.

ClientStateVar accepts invalid JavaScript identifiers and emits broken hook code

1 participant