app.storage.tab not unique for Duplicate tabs #3867
-
QuestionI did a quick experiment to test app.storage.tab storage (below), running on localhost. Every new tab that connects prints "new!..." with a unique value, but any tab I create with "Duplicate" in Chrome (or "Duplicate Tab" in Edge) prints "already..." with the same value as the duplicated tab. This isn't mentioned on the storage page, not sure if this is a bug or expected behavior? Is there any way to get unique storage for Duplicate tabs? @ui.page('/')
async def index(request: Request) -> None:
await ui.context.client.connected()
chat_exchanges_key = 'chat_exchanges'
if chat_exchanges_key in app.storage.tab:
print(f'~~~ already set! {app.storage.tab[chat_exchanges_key]}')
else:
x = randint(1, 99)
app.storage.tab[chat_exchanges_key] = x
print(f'~~~ new! setting to {x}') |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Because duplicating tab will create the same tab_id of tabs. |
Beta Was this translation helpful? Give feedback.
-
The reason seems to be that the session storage is copied when duplicating Chrome tabs. Other browsers might behave differently, as this discussion points out:
NiceGUI stores a "__nicegui_tab_id" in the session storage. By copying it, the new tab uses the same tab ID. To me it also feels a bit strange. When duplicating the tab, I wouldn't expect it to share the tab storage with the original tab, because it is - after all - a separate tab. Some users might rely on the fact that there's always only one client interacting with one tab storage. I wonder if there is a way to detect the tab duplication in JavaScript and to reset the tab ID in this case. |
Beta Was this translation helpful? Give feedback.
Because duplicating tab will create the same tab_id of tabs.
ui.label(ui.context.client.tab_id)