reflex icon indicating copy to clipboard operation
reflex copied to clipboard

alert_dialog autoclose when refresh page

Open iBuitron opened this issue 1 year ago β€’ 2 comments

Minimal exmaple

When i load the page first time, it works fine. I click on button and then close.

if i refresh the page, it autoclose without click the button



class AlertDialogState2(rx.State):
    opened: bool = True

    def close_dialog(self):
        print("Closing dialog")
        print(self.opened)
        self.opened = False
        print(self.opened)

# Only the first time prints, on refresh just autoclose

@rx.page(
    "/synonyms/[study_id]",
    # on_load=[QuickbioState.load_qb, RadioItemsState.get_database],
)
def layout() -> rx.Component:
    return rx.alert_dialog.root(
        rx.alert_dialog.content(
            rx.alert_dialog.title("Select a database"),
            rx.box(
                # rx.radio(
                #     items=RadioItemsState.databases,
                # ),
                rx.flex(
                    rx.alert_dialog.action(
                        rx.button(
                            "Search",
                            on_click=AlertDialogState2.close_dialog,
                        ),
                    ),
                ),
            ),
        ),
        open=AlertDialogState2.opened,
    )

iBuitron avatar Nov 05 '24 18:11 iBuitron

https://reflex.dev/docs/library/overlay/alert-dialog/#controlling-alert-dialog-with-state

This behavior is repeated on your website.

When I open a modal, and then refresh the website, the state of the modal (open) remains despite the refresh. Is this expected behavior or a bug? I would expect it to close and not maintain the state after the refresh.

iBuitron avatar Nov 05 '24 18:11 iBuitron

state is maintained across refreshes, if you want to remove that behavior in this case, either don't attach open to the state or reset it on mount

adhami3310 avatar Feb 22 '25 17:02 adhami3310