Skip to content

remove optional dot from event handler name of client state vars#5854

Merged
adhami3310 merged 1 commit intomainfrom
remove-optional-dot-from-event-handler-name
Oct 6, 2025
Merged

remove optional dot from event handler name of client state vars#5854
adhami3310 merged 1 commit intomainfrom
remove-optional-dot-from-event-handler-name

Conversation

@adhami3310
Copy link
Member

No description provided.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

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

Edit Code Review Agent Settings | Greptile

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 6, 2025

CodSpeed Performance Report

Merging #5854 will not alter performance

Comparing remove-optional-dot-from-event-handler-name (54c6f6d) with main (978f5ea)

Summary

✅ 8 untouched

@adhami3310 adhami3310 merged commit b7230bd into main Oct 6, 2025
40 of 41 checks passed
@adhami3310 adhami3310 deleted the remove-optional-dot-from-event-handler-name branch October 6, 2025 21:29
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.

2 participants