Mohamed-512 / Extra-Streamlit-Components

An all in one place, to find complex or just not available components by default on streamlit.
Apache License 2.0
466 stars 59 forks source link

[Feature Request] make CookieManager constructor wait until cookies have been read. #44

Closed fcolecumberri closed 6 months ago

fcolecumberri commented 1 year ago

I am Using extra-streamlit-components==0.1.56. I have noticed that when instantiated, CookieManager takes some time after the constructor returned to read the cookies and if the cookies are attempted to be read, the calls will successfully return like if no cookies were there.

A way I have done to mitigate the problem is the next code:

cookie_manager = stx.CookieManager()
inited = False
while not inited:
    try:
        inited = cookie_manager.get_all()
    except st.errors.DuplicateWidgetID:
        pass
    if not inited:
        sleep(0.02)

However polling is not ideal. Also this only works because the _xsrf token is always generated by streamlit regardless of the necessity so I know I will never be stuck in the loop.

ZupoLlask commented 11 months ago

I think you'll stumble into other issues using that approach.

I'm not sure if something changed with Streamlit execution model since this component was originally developed, but currently there are issues related with reruns and cookies not being returned deterministically without some hacking...

alessandro-ceccarelli commented 10 months ago

How can you avoid the infinite reload issue with cookies? It seems like sometimes - even on 2GB + servers. - the page reloads almost indefinitely for cookies.

benlindsay commented 7 months ago

This looks related to the issue I just made: https://github.com/Mohamed-512/Extra-Streamlit-Components/issues/58

Mohamed-512 commented 6 months ago

Should be fixed in 0.1.70