Skip to content

rx.call_script does not fire from on mount/unmount events #6555

@adlee-zag

Description

@adlee-zag

Describe the bug
When an event handler that yields rx.call_script is bound to a component's on_mount or on_unmount event triggers, the JavaScript never executes in the browser. The backend handler fires (confirmed via print), but the yielded rx.call_script is silently dropped.

To Reproduce
Bind an event handler that yields rx.call_script to a component's on_mount or on_unmount trigger.

  • Code/Link to Repo:
import reflex as rx


class State(rx.State):
    show: bool = False

    @rx.event
    def toggle(self):
        self.show = not self.show

    @rx.event
    def on_box_mount(self):
        print('EVENT HANDLER FIRED — this prints to terminal')
        yield rx.call_script('console.log("MOUNTED — this should appear in browser console")')

    @rx.event
    def on_box_unmount(self):
        print('UNMOUNT HANDLER FIRED — this prints to terminal')
        yield rx.call_script('console.log("UNMOUNTED — this should appear in browser console")')


def index() -> rx.Component:
    return rx.vstack(
        rx.button('Toggle Box', on_click=State.toggle),
        rx.cond(
            State.show,
            rx.box(
                rx.text('I am mounted — check browser console for "MOUNTED" log'),
                padding='20px',
                background='lightgreen',
                on_mount=State.on_box_mount,
                on_unmount=State.on_box_unmount,
            ),
        ),
        padding='50px',
        spacing='4',
    )


app = rx.App()
app.add_page(index)

Expected behavior
rx.call_script should fire when called from a mount/un_mount event handler

Specifics (please complete the following information):

  • Python Version: 3.12.10
  • Reflex Version: 0.9.2.post1
  • OS: macOS 15.7.5 (24G624)
  • Browser (Optional): Chrome 148.0.7778.97 and Safari 26.4 (20624.1.16.18.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions