taipy
taipy copied to clipboard
BUG- If user has two windows open on the same browser, callbacks (`navigate`, `download`) happen on both windows
Description
It's a funny one and pretty sure it happens because we call navigate
to the same user, and we end up calling it twice
Does not happen if you have two different browsers, because then you'll have two different users ID.
How to reproduce Example code:
from taipy.gui import navigate, Gui
def go_to_google(state):
navigate(state, to="https://www.google.com/")
page = """
<|button|label=navigate to google|on_action=go_to_google|>
"""
Gui(
page=page
).run(debug=True, use_reloader=True)
Open a browser (in my case it was Firefox) to your Taipy app, open another window to it. Make sure you have TWO separate windows accessing the app ON THE SAME BROWSER.
If you click the button while having two windows open on the same browser (Therefore same user session), you'll have two tabs opening to google in each browser window
Expected behavior
Clicking on the navigate to google
button should only open a tab in the window which the button was clicked
Runtime environment Please specify relevant indications.
- Taipy 3.1.0
- Browser: Firefox
There might be the same behavior using the download function
There might be the same behavior using the download function
Oooooh that explains why I've been downloading multiple things in my projects....
from taipy.gui import navigate, Gui, download
def go_to_google(state):
navigate(state, to="https://www.google.com/")
def download_callback(state):
# have a main.py file in your working directory
download(state, "main.py")
page = """
<|button|label=navigate to google|on_action=go_to_google|>
<|button|label=Download|on_action=download_callback|>
"""
Gui(
page=page
).run(debug=True, use_reloader=True, port=2552)
Yes, it is also an issue.
it wouldn't happen if you use 2 different browsers The client id is stored in the browser's local storage which is shared between different tabs/windows of the same browser
it wouldn't happen if you use 2 different browsers The client id is stored in the browser's local storage which is shared between different tabs/windows of the same browser
Yes, I thought that was the case and tested if that would work as well. Sorry, should've added that to the description, will edit it. Unsure if that's something you would want to address or not, so decided to raise at least to have the discussion
However here's a case in favour of fixing this:
Say I have two pages Home
and About
and in the About
section I have some links. I have one window open on Home
and another on About
. I click a link on About
then suddenly two tabs to the link are opened. Similar to the Download control
I have many tabs pointing to my application when developing or even when the application is deployed; by mistake, I can have two tabs on the same application.
Hello team,
Am not sure, does this fall under the same category or not.
I was thinking when I open the same url, I should get different text, but doesn't happen. I am trying it on edge and firefox.
Hello team, Am not sure, does this fall under the same category or not.
I was thinking when I open the same url, I should get different text, but doesn't happen. I am trying it on edge and firefox.
Heya! I believe this not exactly related. I think you're using a global variable to store the input control, so it's shared across all users. But either way, the instances between browsers are the same because they're considered the same user. So if you open a firefox, every window and tab in that session is the same user. If you open a private window or another browser, then its another user. That's intended TaiPy design if I am not mistaken.
If you want to understand this better try this:
from taipy.gui import get_state_id
def on_init(state):
print(f"New User: {get_state_id(state)}")
And try opening/closing multiple windows with differnet browsers and seeing your output
@Yuvraj-Dhepe Yes, it should be different. Each browser has local storage; Taipy is using that to know whether this is still the same user/state.
Opening this application in two separate browsers should show different views. If not, please provide some code so we can replicate it.
@FlorianJacta as you can see in the gif, I used firefox and microsoft edge (private window) and the code is simply as mentioned in the jupyter nb on Taipy Website
from taipy.gui import Gui
text = "Original text"
page = """
# Getting started with Taipy GUI
My text: <|{text}|>
<|{text}|input|>
"""
Gui(page).run(port = 8080)
However still with different browsers I get the same text op when I type in any of the text space in any of the 2 browsers. But pls note I am running this code in jupyter notebook in vscode which is running on my WSL-windows :sweat_smile:
So basically when I run the code, vscode forwards the 8080 port to my local machine and in this local machine I opened 2 browsers firefox and edge(private windows). I was expecting the client is same for the edge browser and the text should be connected their and firefox text shouldn't change.
But in gif, you see both browsers text are connected and changing, even if one of them changes.
But maybe I can try printing out what @gbritoda suggested, maybe then I get more context about what's happening.
Are you using a Jupyter Notebook?
Are you using a Jupyter Notebook?
Yup
So, this is why. I think you should have in your logs that Taipy is running with only one client
Yup so that's true, I have to start running a .py file to use the functionality. If I use a ipynb, it's considered as a single user, even if I use different browsers.
Thanks for the clarification.