reflex-dev / reflex-dev/reflex

EventHandler redesign: awaitable semantics

Open
#6,223 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
28.9k
Forks
1.8k
Avg merge
2d 2h
Merged PRs (30d)
170

Description

Summary

Redesign @rx.event as the central registration mechanism independent of any state class. Registered events go into a global event list used by the EventProcessor.

Key Changes

  • EventHandlers are always awaitable (never generators externally). Generators can be used as the event function, but the external API for calling them is always awaitable.
  • Calling an EventHandler applies partial args and returns a new copy. To actually execute, you must await the handler or create a task from it.
  • With an EventContext on the stack: execute in-context as a task, return an EventHandler with an active awaitable task.
  • Without a context: collect arguments and return an EventHandler with partial args and no task (awaiting is an error).
  • Yielded events are requeued on the backend rather than returned to the caller. Internal machinery constructs a delta and sends it to the frontend.
  • Return values are sent back in the final delta — eventually allowing event calls to return a promise on the frontend.

Why

The global event registry directly produces the surface for event handlers as HTTP endpoints with OpenAPI spec, enabling agent access and external tool integration. This keeps the __call__ signature consistent while supporting both immediate execution and deferred invocation.

Part of the Reflex Framework Roadmap — Section 1b.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the @rx.event registration path, EventHandler, EventProcessor, global event list, and HTTP/OpenAPI endpoint generation described in the issue. Review the roadmap's Section 1b and existing tests around event execution before defining the design. Done means the listed awaitable, partial-argument, context, requeueing, and return-value semantics are implemented and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.