fix: set_focus/blur_focus args stripped by get_handler_args for stateless handlers#6314
Conversation
…less handlers get_handler_args() used `len(args) > 1` assuming all handlers have a `self` parameter from a State class. Server-side events like _set_focus have no state, so their single `ref` parameter was incorrectly stripped, producing an empty payload and a frontend TypeError: Cannot read properties of undefined (reading ref).
Greptile SummaryThis PR fixes a bug in Confidence Score: 5/5This PR is safe to merge — it's a minimal, well-targeted bug fix with matching unit and integration tests. The one-line logic change is consistent with the same No files require special attention.
|
| Filename | Overview |
|---|---|
| packages/reflex-base/src/reflex_base/event/init.py | One-line targeted fix: replaces len(args) > 1 with len(args) > n_self_args in get_handler_args, using the same pattern already applied consistently elsewhere in the file. |
| tests/units/test_event.py | Adds test_focus_event_chain_preserves_args to verify the ref arg survives EventChain.create for set_focus/blur_focus, directly covering the regression path. |
| tests/integration/test_server_side_event.py | Adds a browser-level integration test (test_set_focus) that clicks a button calling rx.set_focus and polls for the target input becoming the active element. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["EventSpec with stateless handler\n(e.g. _set_focus, _blur_focus)"] --> B["get_handler_args(event_spec)"]
B --> C{"handler.state is not None?"}
C -- "Yes (State-bound handler)" --> D["n_self_args = 1"]
C -- "No (Stateless/server-side)" --> E["n_self_args = 0"]
D --> F{"len(args) > 1?"}
E --> G{"len(args) > 0?"}
F -- "True" --> H["Return event_spec.args ✅"]
F -- "False" --> I["Return () — correctly empty"]
G -- "True" --> J["Return event_spec.args ✅\n(ref arg preserved — BUG FIX)"]
G -- "False" --> K["Return () — correctly empty"]
Reviews (1): Last reviewed commit: "fix: set_focus/blur_focus args stripped ..." | Re-trigger Greptile
|
The test is flaky, its fix is in work in this pr #6307 |
get_handler_args() used
len(args) > 1assuming all handlers have aselfparameter from a State class. Server-side events like _set_focus have no state, so their singlerefparameter was incorrectly stripped, producing an empty payload and a frontend TypeError: Cannot read properties of undefined (reading ref).All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features: