You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're building an app with solara that involves querying a database and presenting that information to the user.
We have noticed that in a number of places where we're using reactive states ( state = solara.reactive() ), there is an intermittent issue where users on different machines will be presented with the information from a different user's reactive state.
e.g. A user does a search, the result of that search is saved to a reactive state, a different user on a different machine will end up with that search result.
We noticed it initially when using reactive states to identify users with a username - someone would open up the app, and be presented with someone else's username.
With solara.use_state() you can enter a key='x' as an argument, and we do not get the issue with use_states because of that, as we can assign a unique key to each user. So there is definitely a unique state for each user and they don't end up interacting.
I think that if we could do that with solara.reactive() as well, that would enable us to resolve the issue. (but I'm not 100% sure how solara.reactive() works under the hood, so am unsure if this is possible.)
If you need any more details or there is anything else we can do to help resolve this issue please do let us know - we are quite deep into this project and this issue does not appear to be something we can easily resolve on our own. (except by changing everything to use_states, and that's not really ideal because of the limitations of use_states)
Fully holding out for the possibility that we are simply using solara.reactive() in an unexpected way, but we have been using solara for 6 months now and are fairly familiar with the way solara wants to be used.
Thankyou very much and all the best.
The text was updated successfully, but these errors were encountered:
This is something that isn't documented, but is caused by parsing something that is pre-evaluated into a global reactive. This can happen when you do something like:
sl.reactive({}) :: the dict is already made
sl.reactive(pd.read_csv(filename)) :: the dataframe is made and then referenced by each reactive instance
To check if this is the case, open two sessions of your app and print the hex(id(state.value)). Both of these will be the same between both sessions.
A way to resolve this is by running a startup function to set the initial variable, either by sl.use_effect at your top-level component, or solara.lab.on_kernel_start.
and it is set to a unique starting value per kernel/user with:
@solara.lab.on_kernel_startdefon_start():
state.set(get_initial_thing())
@solara.componentdefPage():
...
# do this OR the kernel_start method, not bothdefeffect_to_run():
state.set(get_initial_thing())
solara.use_effect(effect_to_run, dependencies=[]) # runs once after first render, never again
...
You can add cleanup functions as well to each, although it is much simpler on the on_kernel_start decorator.
Hi @rileythai for the suggested solution! And thank you @daoslies for making me aware of this problem that I could be facing very soon indeed.
It is strange that this is not documented anywhere, sounds like a pretty big deal.
Is there an official way to handle this of a preferred workaround @maartenbreddels@iisakkirotko ?
I like the solution stated above, is it relatively safe to use given it comes from solara.lab, and initiating reactive variable is a core feature..
We're building an app with solara that involves querying a database and presenting that information to the user.
We have noticed that in a number of places where we're using reactive states ( state = solara.reactive() ), there is an intermittent issue where users on different machines will be presented with the information from a different user's reactive state.
e.g. A user does a search, the result of that search is saved to a reactive state, a different user on a different machine will end up with that search result.
We noticed it initially when using reactive states to identify users with a username - someone would open up the app, and be presented with someone else's username.
With solara.use_state() you can enter a key='x' as an argument, and we do not get the issue with use_states because of that, as we can assign a unique key to each user. So there is definitely a unique state for each user and they don't end up interacting.
I think that if we could do that with solara.reactive() as well, that would enable us to resolve the issue. (but I'm not 100% sure how solara.reactive() works under the hood, so am unsure if this is possible.)
If you need any more details or there is anything else we can do to help resolve this issue please do let us know - we are quite deep into this project and this issue does not appear to be something we can easily resolve on our own. (except by changing everything to use_states, and that's not really ideal because of the limitations of use_states)
Fully holding out for the possibility that we are simply using solara.reactive() in an unexpected way, but we have been using solara for 6 months now and are fairly familiar with the way solara wants to be used.
Thankyou very much and all the best.
The text was updated successfully, but these errors were encountered: