feat: allow explicit only event handlers - #7033
Conversation
Greptile SummaryThe PR adds an opt-in mode in which only methods decorated with
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the current context-local resolution and in-progress config publication address all three previously reported configuration-selection defects.
|
| Filename | Overview |
|---|---|
| packages/reflex-base/src/reflex_base/config.py | Resolves State flags from the in-progress config load or active RegistrationContext, addressing stale, ordering-dependent, and cross-context selection. |
| packages/reflex-base/src/reflex_base/event/init.py | Marks functions processed by every supported event decorator form for explicit handler discovery. |
| reflex/state.py | Filters user-defined State handlers by the event marker when explicit mode is enabled while retaining existing behavior for built-in states. |
| tests/units/test_state.py | Covers explicit handler registration and the three previously reported configuration-selection failures. |
| tests/units/test_event.py | Verifies that plain, configured, and background event decorators all apply the event marker. |
Reviews (6): Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." | Re-trigger Greptile
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 5 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
b2a522f to
945a53f
Compare
There was a problem hiding this comment.
All reported issues were addressed across 8 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
masenf
left a comment
There was a problem hiding this comment.
great, this gives us a lever and a chicken switch for eventually defaulting to requiring the decorator for event handlers.
need to ensure that reflex-enterprise's auth plugin and other integration points can still work with this new structure, but it seems like it would at first glance.
|
|
||
| Adding the `@rx.event` decorator above the event handler is strongly recommended. This decorator enables proper static type checking, which ensures event handlers receive the correct number and types of arguments. | ||
|
|
||
| By default, every public method of a state (one whose name does not start with `_`) is treated as an event handler, whether or not it is decorated. To make `@rx.event` mandatory and keep undecorated public methods as plain Python helpers, enable `state_explicit_event_handlers` in `rxconfig.py`: |
There was a problem hiding this comment.
Might also become default one day, following the Zen of Python
Explicit is better than implicit.
There was a problem hiding this comment.
yeah, i wanted to go the same route as i did with state_auto_setters.
- introduce a flag to enable explicit mode - let feature stabilize and some projects adopt
- change the default to explicit
- drop implicit mode
Closes #7032