rename Event to ReflexEvent#5735
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR fixes a critical production bug by renaming the JavaScript Event constructor to ReflexEvent throughout the codebase. The change addresses issue #5726 where rx.call_script with callbacks would fail in production environments due to a naming conflict with the browser's native DOM Event constructor.
The root problem was that Reflex generated JavaScript code calling Event(...) as a function, but the browser's native Event constructor must be called with the new operator. This worked fine in development but caused TypeError: Failed to construct Event: Please use the new operator exceptions in production builds where minification made this conflict more apparent.
The PR systematically updates six files across the codebase:
- Backend changes: Updates
reflex/constants/compiler.pyto change theTO_EVENTconstant from "Event" to "ReflexEvent", modifiesreflex/event.pyto useReflexEventin event creation logic, updatesreflex/utils/format.pyto generateReflexEvent()calls instead ofEvent()calls, and changesreflex/components/component.pyto reference "ReflexEvent" in useCallback dependencies - Frontend changes: Updates
reflex/.templates/web/utils/state.jsto rename theEventfunction toReflexEventand all its references, and modifiesreflex/compiler/templates.pyto generateReflexEventconstructor calls in compiled templates
This change maintains full backward compatibility at the API level while eliminating the JavaScript namespace collision. The fix ensures that event handling works consistently across both development and production environments, particularly for features like rx.call_script with callback functionality.
Confidence score: 5/5
- This PR is extremely safe to merge with minimal risk as it fixes a critical production bug without breaking existing functionality
- Score reflects a thorough, systematic fix across all relevant files with clear understanding of the root cause and comprehensive solution
- No files require special attention as the changes are straightforward variable/function renamings with consistent implementation across the entire codebase
6 files reviewed, no comments
CodSpeed Performance ReportMerging #5735 will not alter performanceComparing Summary
|
fixes #5726