Skip to content

Preserve registered callbacks passed through state events - #8078

Open
harsh21234i wants to merge 7 commits into
reflex-dev:mainfrom
harsh21234i:fix/4894-event-callback-arguments
Open

harsh21234i wants to merge 7 commits into
reflex-dev:mainfrom
harsh21234i:fix/4894-event-callback-arguments

Conversation

@harsh21234i

@harsh21234i harsh21234i commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4894.

Passing an uncalled handler to another event tried to compile it as a no-argument conditional event. A partially applied event declared in a page could reach the receiving handler as a plain browser object, so forwarding it to rx.call_script lost the callback.

Bind uncalled handlers as partial events. When a receiving state handler's parameter is annotated as an event callback, restore the browser's event object through the registration context. Ordinary payload dictionaries keep their existing semantics. Bound arguments are validated against the registered handler and keep their names when a subsequent trigger supplies the remaining arguments.

The new Chromium regression fails on main and exercises server-initiated forwarding, browser-initiated forwarding and partial application. A unit regression covers registry resolution, named binding, ordinary payloads and malformed callback references.

  • 727 event unit tests passed.
  • 4 Chromium call-script tests passed.
  • 5 focused cases passed on Python 3.11.
  • Pre-commit passed.

View guided diff

@harsh21234i
harsh21234i requested a review from a team as a code owner December 1, 2026 13:48
@FarhanAliRaza FarhanAliRaza added the bug Something isn't working label Dec 1, 2026 — with ChatGPT Codex Connector

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 5 files

View guided diff | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; no new actionable issue remains.

Summary

Preserves registered callbacks passed through state events.

  • State events can forward callbacks while keeping their bound arguments.

Reviews (2) · Last reviewed commit: "Describe every fix in the news fragment" · Reviewed by Greptile

@codspeed

codspeed Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.01%

2 warnings

⚠️ 20 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

❌ 1 regressed benchmark
✅ 145 untouched benchmarks
⏩ 8 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_proxy_list_mutation 9.3 ms 9.6 ms -4.01%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing harsh21234i:fix/4894-event-callback-arguments (832f695) with main (8e0e881)

Open in CodSpeed

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. ↩

@FarhanAliRaza FarhanAliRaza added the on deck PRs lined up to review / merge next label Dec 1, 2026
A string bound to a forwarded callback went through LiteralVar.create,
which parses Var markup. A client could send <reflex.Var>hello</reflex.Var>
and freeze the worker in that parser. Bind each value as a JSON Var
instead, with "<" escaped so the markup parser never sees it when
call_script embeds the callback in its script.
Drop _InvalidEventCallbackError and the two clauses that re-raised it.
A callback that cannot be restored now raises ValueError, so the payload
falls back to the values as sent and the failure is logged, the same as
any argument that does not match its annotation.
No caller passes an event handler to add_args, so its signature goes back
to *args: Var. The one caller that needs it, EventHandler.__call__, turns
an uncalled handler argument into a partial event itself.
Pin the payload compiled for a handler passed uncalled as an argument,
and that a trigger fills the parameter a keyword binding left free.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working on deck PRs lined up to review / merge next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot pass an EventHandler through an EventHandler

2 participants