Skip to content

rename Event to ReflexEvent#5735

Merged
adhami3310 merged 2 commits into
mainfrom
rename-Event-to-ReflexEvent
Aug 25, 2025
Merged

rename Event to ReflexEvent#5735
adhami3310 merged 2 commits into
mainfrom
rename-Event-to-ReflexEvent

Conversation

@adhami3310

Copy link
Copy Markdown
Member

fixes #5726

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.py to change the TO_EVENT constant from "Event" to "ReflexEvent", modifies reflex/event.py to use ReflexEvent in event creation logic, updates reflex/utils/format.py to generate ReflexEvent() calls instead of Event() calls, and changes reflex/components/component.py to reference "ReflexEvent" in useCallback dependencies
  • Frontend changes: Updates reflex/.templates/web/utils/state.js to rename the Event function to ReflexEvent and all its references, and modifies reflex/compiler/templates.py to generate ReflexEvent constructor 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

Edit Code Review Bot Settings | Greptile

@codspeed-hq

codspeed-hq Bot commented Aug 25, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #5735 will not alter performance

Comparing rename-Event-to-ReflexEvent (22c7e18) with main (fe9551d)

Summary

✅ 8 untouched benchmarks

@adhami3310 adhami3310 merged commit 817b8b4 into main Aug 25, 2025
41 checks passed
@adhami3310 adhami3310 deleted the rename-Event-to-ReflexEvent branch August 25, 2025 18:22
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.

rx.call_script with callback is broken in prod env

2 participants