Skip to content

Conversation

@adhami3310
Copy link
Member

No description provided.

@linear
Copy link

linear bot commented Oct 17, 2025

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

Fixed memoization issue where WindowEventListener event handlers weren't properly memoized when used inside memoized components.

Key Changes:

  • Added hooks field to store memoized event trigger hooks from StatefulComponent._fix_event_triggers()
  • Overrode create() method to call _fix_event_triggers() and store resulting hooks
  • Modified add_hooks() to merge stored memoized hooks with generated useEffect hooks
  • Changed event handler wrapping in useEffect: const fn = {Var.create(event_trigger)} ensures proper variable creation
  • Removed _var_type="str" from Var creation in hooks (now inferred correctly)

How It Works:
When WindowEventListener is created, _fix_event_triggers() processes all event handlers through StatefulComponent's memoization logic, generating useCallback hooks. These are stored and then merged with the useEffect hooks that register window event listeners, ensuring stable function references across re-renders.

Confidence Score: 4/5

  • Safe to merge with minimal risk - fix follows established patterns
  • Implementation correctly applies the memoization pattern used elsewhere in the codebase (Upload, Match components). The fix properly wraps event triggers using Var.create() and stores memoized hooks. Minor concern is the change from explicit _var_type to inferred typing, but this aligns with the framework's typing system.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
reflex/components/core/window_events.py 4/5 Adds memoization support for window event listeners by storing memoized event trigger hooks and properly wrapping event handlers in useCallback
pyi_hashes.json 5/5 Updates hash for window_events.pyi to reflect changes to the module's type definitions

Sequence Diagram

sequenceDiagram
    participant User as Developer
    participant WEL as WindowEventListener
    participant SC as StatefulComponent
    participant Compiler as Compiler
    participant Browser as Runtime

    User->>WEL: create with event handler
    WEL->>SC: _fix_event_triggers
    SC->>SC: Generate memoized triggers
    SC-->>WEL: Return hooks list
    WEL->>WEL: Store hooks
    WEL-->>User: Component ready

    Compiler->>WEL: add_hooks
    WEL->>WEL: Merge stored hooks
    WEL->>WEL: Generate useEffect for events
    WEL-->>Compiler: Return hooks

    Compiler->>Browser: Emit React code
    Browser->>Browser: useCallback executed
    Browser->>Browser: useEffect executed
    Browser->>Browser: addEventListener
Loading

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 17, 2025

CodSpeed Performance Report

Merging #5899 will create unknown performance changes

Comparing khaleel/eng-8034-rxwindow_event_listener-on_key_down-is-rendering-raw (6d85b6d) with main (49dacfa)

Summary

⚠️ No benchmarks were detected in both the base of the PR and the PR.
Please ensure that your benchmarks are correctly instrumented with CodSpeed.

Check out the benchmarks creation guide

⏩ 8 skipped1

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link

@lilpomm lilpomm left a comment

Choose a reason for hiding this comment

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

Gracias por su comprensión

@adhami3310 adhami3310 merged commit fb19fb4 into main Oct 17, 2025
46 of 47 checks passed
@adhami3310 adhami3310 deleted the khaleel/eng-8034-rxwindow_event_listener-on_key_down-is-rendering-raw branch October 17, 2025 17:16
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.

4 participants