remove optional dot from event handler name of client state vars#5854
remove optional dot from event handler name of client state vars#5854adhami3310 merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Greptile Overview
Summary
This PR fixes a regex pattern in the client state variable system to properly handle JavaScript optional chaining syntax. The change modifies the `set_value` method in `ClientStateVar` to update a regex pattern from `r"\[\".*\"\]"` to `r"(\?\.)?\[\".*\"\]"`, adding an optional group `(\?.)?` to match optional chaining operators (`?.`) that may appear before bracket notation.The issue addressed occurs when client state variables use optional chaining syntax in event handler names (e.g., obj?.['property']). The original regex only stripped bracket notation patterns like ['something'], but when optional chaining was present, the ?. portion remained in the cleaned string. This resulted in malformed argument names being passed to the ArgsFunctionOperationBuilder, which creates JavaScript functions for state setters. The incomplete cleaning would generate invalid JavaScript syntax, causing runtime errors.
This fix integrates with Reflex's client state system, which allows state variables to be managed on the frontend. When these variables need setter functions, the system parses the variable names and strips event handler patterns to create clean argument names for the generated JavaScript functions. The updated regex ensures both standard bracket notation and optional chaining patterns are properly removed during this cleaning process.
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| reflex/experimental/client_state.py | 4/5 | Updated regex pattern to handle optional chaining syntax in client state variable event handler names |
Confidence score: 4/5
- This PR is safe to merge with minimal risk as it addresses a specific parsing issue in client state variables
- Score reflects a targeted fix for a well-defined problem with clear regex pattern improvement
- No files require special attention - the change is localized and straightforward
1 file reviewed, no comments
CodSpeed Performance ReportMerging #5854 will not alter performanceComparing Summary
|
No description provided.