Skip to content

Invalid JavaScript Code Generation with EventHandler args_spec Using rx.Var Expressions #5741

@LeoGrosjean

Description

@LeoGrosjean

Describe the bug
Reflex generates invalid JavaScript code when using a custom args_spec in an EventHandler that returns rx.Var(f"{event}?.formData"). The generated code places an expression (_event?.formData) in an argument list, causing a JavaScript syntax error during compilation.

To Reproduce
Steps to reproduce the behavior:

  1. Create a custom event signature function:
from reflex.vars import ObjectVar
from reflex.event import JavascriptInputEvent
from typing import Dict, Any

def submit_signature(
    event: ObjectVar[JavascriptInputEvent],
) -> tuple[Var[Dict[str, Any]], Var[str]]:
    return (
        rx.Var(f"{event}?.formData"),
        rx.Var(f"{event}?.retrievedSchema.title"),
    )
  1. Create a component with the EventHandler:
class RjsfReflex(rx.Component):
    # ... other component properties
    on_submit: rx.EventHandler[submit_signature]
    # ...
  1. Use the component with ClientStateVar:
var_name = ClientStateVar.create("var_name_js", "dummy_data")

# This triggers the bug
Form(
    on_submit=lambda data: rx.call_function(ClientStateVar.set_value(data))
)
  1. Run reflex run and observe the JavaScript compilation error

Expected behavior
The component should generate valid JavaScript code that properly handles form data extraction and submission without syntax errors. The args_spec should allow accessing nested properties like formData from the event object.

Screenshots
Error output:

[plugin:vite:oxc] Expected `,` but found `=>`
/Users/leoh/PycharmProjects/rjsf-reflex/rjsf_reflex_demo/.web/app/routes/_index.jsx:76:175
`,` expected
74 |    
75 |    return (
76 |      jsx(Form,{className:"schema-form",css:({ ["maxWidth"] : "100%" }),id:"no",onSubmit:((_event) => (addEvents([(Event("_call_function", ({ ["function"] : ((_event?.formData) => (refs['_client_state_setResult'](_event?.formData))), ["callback"] : null }), ({  })))], [_event], ({  })))),ref:ref_no,schema:reflex___state____state__rjsf_reflex_demo___rjsf_reflex_demo____state.schema_rx_state_,validator:validator},)
   |                                                                                                                                                                                 ^^
77 |  

Specifics (please complete the following information):

  • Python Version: 3.12.8
  • Reflex Version: 0.8.8
  • OS: macOS sequoia

Additional context

  • This occurs when trying to create a React JSON Schema Form (RJSF) wrapper component
  • The problem appears to be that Reflex treats rx.Var(f"{event}?.formData") as an expression but places it in a context where a parameter name is expected

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions