Skip to content

bug: Web mode multi-tab session cross-contamination — events from one tab affect another tab #6512

@ihmily

Description

@ihmily

Duplicate Check

Describe the bug

When running a Flet app in web mode (ft.AppView.WEB_BROWSER), opening the same URL in multiple browser tabs causes cross-tab session interference. Specifically:

  1. Open Tab1 at http://127.0.0.1:6006 — the app works correctly.
  2. Open Tab2 at the same URL (via "Duplicate Tab", Ctrl+clicking the address bar and pressing Enter, or other methods that cause sessionStorage inheritance).
  3. Go back to Tab1 and click any button — Tab1's UI does not update, but Tab2's UI changes instead.

The root cause is that the server-side session reuse logic in flet_app.py does not check whether the existing session's connection is still alive before handing it to a new WebSocket connection.

When a second browser tab inherits the same _flet_session_id from window.sessionStorage (which is standard HTML5 behavior for duplicated tabs), the server blindly reuses the existing Session object and calls attach_connection(), which overwrites Session.__conn to point to Tab2's FletApp. After that, all UI patches — including those triggered by Tab1's events — are sent exclusively to Tab2.

Code sample

Code
import flet as ft

def main(page: ft.Page):
    page.title = "Flet counter example"
    page.vertical_alignment = ft.MainAxisAlignment.CENTER

    input = ft.TextField(value="0", text_align=ft.TextAlign.RIGHT, width=100)

    def minus_click(e):
        input.value = str(int(input.value) - 1)

    def plus_click(e):
        input.value = str(int(input.value) + 1)

    page.add(
        ft.Row(
            alignment=ft.MainAxisAlignment.CENTER,
            controls=[
                ft.IconButton(ft.Icons.REMOVE, on_click=minus_click),
                input,
                ft.IconButton(ft.Icons.ADD, on_click=plus_click),
            ],
        )
    )

ft.run(
    main=main,
    view=ft.AppView.WEB_BROWSER,
    web_renderer=ft.WebRenderer.CANVAS_KIT,
    host="0.0.0.0",
    port=6006
)

To reproduce

  1. Run the above code: python demo.py
  2. Browser automatically opens http://127.0.0.1:6006 (Tab1). Click + / - buttons — works fine.
  3. Open a second tab to the same URL (use "Duplicate Tab" or copy-paste the URL in a new tab — any method that causes sessionStorage to be inherited).
  4. Go back to Tab1 and click + or -.
  5. Observe: Tab1's counter does not change. Tab2's counter changes instead.

Expected behavior

Each browser tab should have an independent session. Clicking buttons in Tab1 should only affect Tab1's UI, and Tab2 should be completely isolated.

Screenshots / Videos

Captures
_2026_05_21_14_35_48_538.mp4

Operating System

Windows

Operating system details

include Linux 、Mac

Flet version

0.85.1

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    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