Skip to content

Conversation

@veerababu1729
Copy link
Contributor

feat: Improve error message for invalid triggers by listing valid options

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • New feature (non-breaking change which adds functionality)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you successfully ran tests with your changes locally?

Description

This PR improves the developer experience when an invalid event trigger is used on a component. Previously, the error message only stated that the trigger was invalid. Now, it lists all valid triggers for that specific component, making it much easier for developers to identify the correct trigger name (e.g., seeing on_mouse_enter instead of trying on_hover).

Proof of Fix

I verified this change using a reproduction script that attempts to pass an invalid trigger (on_invalid_trigger) to a rx.box component.

Before:

ValueError: The Box does not take in an `on_invalid_trigger` event trigger. If Box is a third party component make sure to add `on_invalid_trigger` to the component's event triggers. visit https://reflex.dev/docs/wrapping-react/guide/#event-triggers for more info.

After (with this PR):

ValueError: The Box does not take in an `on_invalid_trigger` event trigger. Valid triggers for Box: ['on_blur', 'on_click', 'on_context_menu', 'on_double_click', 'on_focus', 'on_mount', 'on_mouse_down', 'on_mouse_enter', 'on_mouse_leave', 'on_mouse_move', 'on_mouse_out', 'on_mouse_over', 'on_mouse_up', 'on_scroll', 'on_scroll_end', 'on_unmount']. If Box is a third party component make sure to add `on_invalid_trigger` to the component's event triggers. visit https://reflex.dev/docs/wrapping-react/guide/#event-triggers for more info.

closes #4883

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 2, 2025

Greptile Overview

Greptile Summary

Enhanced error message for invalid event triggers by listing all valid triggers for the component, significantly improving developer experience. The change helps developers quickly identify the correct trigger name instead of guessing.

  • Added sorted list of valid triggers to error message when invalid on_* trigger is used
  • Minor optimization opportunity: reuse already-fetched component_specific_triggers instead of calling get_event_triggers() again

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk - it's a straightforward enhancement to error messaging
  • Score reflects a simple, well-focused change that improves developer experience without altering core logic. One minor optimization opportunity exists (redundant method call), but it doesn't affect correctness or introduce bugs
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
reflex/components/component.py 4/5 Added valid trigger list to error message for invalid event triggers; minor inefficiency with redundant method call

Sequence Diagram

sequenceDiagram
    participant User
    participant Component.__init__
    participant Component.get_event_triggers
    
    User->>Component.__init__: Create component with invalid trigger (e.g., on_invalid_trigger)
    Component.__init__->>Component.get_event_triggers: Fetch event triggers (line 746)
    Component.get_event_triggers-->>Component.__init__: Return triggers dict
    
    Component.__init__->>Component.__init__: Iterate through kwargs
    Component.__init__->>Component.__init__: Check if key starts with "on_"
    Component.__init__->>Component.__init__: Key not in component_specific_triggers
    
    Note over Component.__init__: NEW: Fetch and sort valid triggers
    Component.__init__->>Component.get_event_triggers: Get triggers again (line 761)
    Component.get_event_triggers-->>Component.__init__: Return triggers dict
    Component.__init__->>Component.__init__: Sort trigger keys
    
    Component.__init__->>Component.__init__: Build error message with valid triggers list
    Component.__init__->>User: Raise ValueError with helpful message
Loading

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.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 2, 2025

CodSpeed Performance Report

Merging #6015 will not alter performance

Comparing veerababu1729:fix/issue-4883-invalid-trigger-error (3cbabd4) with main (b2ed9b4)

Summary

✅ 8 untouched

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

thank you for your contribution ☺️

@masenf masenf merged commit c60147b into reflex-dev:main Dec 2, 2025
46 of 47 checks passed
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.

Improve Error Message For Invalid Triggers

2 participants