Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated tabs interfere with each other during background events #4605

Open
TimChild opened this issue Jan 8, 2025 · 1 comment · May be fixed by #4607
Open

Duplicated tabs interfere with each other during background events #4605

TimChild opened this issue Jan 8, 2025 · 1 comment · May be fixed by #4607
Assignees
Labels
bug Something isn't working

Comments

@TimChild
Copy link
Contributor

TimChild commented Jan 8, 2025

Describe the bug
If a new tab is opened by duplicating the first, and a background task is started in both tabs, the first (by order of event trigger) tab stops seeing updates.

To Reproduce
Steps to reproduce the behavior:

Here's the code that I show in the video clip below.

import asyncio
import reflex as rx


class State(rx.State):
    state_value: str = "Initial value"

    @rx.event(background=True)
    async def do_something(self):
        async with self:
            self.state_value = "Initial change"
        await asyncio.sleep(2)
        async with self:
            self.state_value = "Final change"


@rx.page(route="/duplicate_tabs_issue", title="Duplicate tabs issue")
def index() -> rx.Component:
    return rx.container(
        rx.vstack(
            rx.markdown("Minimal example to demonstrate issues with duplicated tab in Chrome."),
            rx.markdown("`state.router.session.client_token` is not unique per tab when tab."),
            rx.text(f"state.router.session.client_token: {rx.State.router.session.client_token}"),
            rx.markdown("However, `state.router.session.session_id` does remain unique per tab."),
            rx.text(f"state.router.session.session_id: {rx.State.router.session.session_id}"),
            rx.divider(),
            rx.text("Somehow the tabs interfere with each other during background tasks."),
            rx.text(
                "Expect to see 'Initial change' followed by 'Final change' after 2 seconds. But that doesn't happen if the button is clicked in the other tab before the first event finishes."
            ),
            rx.button("Do something", on_click=State.do_something),
            rx.text(f"State.state_value: {State.state_value}"),
        )
    )

Expected behavior
Expect that the two tabs behave independently.

Screenshots
Short video clip to show duplication of tabs, and that the background events are interrupted in the first tab by running the event in the second tab.

duplicated_tabs_issue.mp4

In fact, it seems that the second tab get's the update that was intended for first tab (seen in the video by the final_state being set too quickly in the second tab).

Specifics (please complete the following information):

  • Python Version: 3.12
  • Reflex Version: 0.6.5 -> 0.6.7
  • OS: WSL2
  • Browser (Optional): Chrome and Edge (not tried others)

Additional context

You can see that the session_id is unique per tab, but the client_token is not. I'm not sure if that is expected, but seems like it could be relevant.
Note, If the two tabs are opened separately (and don't share a client_token or session_id) then they do both behave independently.

Copy link

linear bot commented Jan 8, 2025

@Lendemor Lendemor self-assigned this Jan 8, 2025
@Lendemor Lendemor added the bug Something isn't working label Jan 8, 2025
@Lendemor Lendemor linked a pull request Jan 8, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants