Spaces:
Sleeping
Sleeping
XQ commited on
Commit ·
aeafb0a
1
Parent(s): b95bdcd
Fix CachedWidgetWarning
Browse files- src/ui/app.py +6 -7
src/ui/app.py
CHANGED
|
@@ -227,14 +227,13 @@ st.markdown('<meta name="robots" content="noindex, nofollow">', unsafe_allow_htm
|
|
| 227 |
# Per-browser session ID — persisted in a cookie so chat history survives
|
| 228 |
# page refreshes. Falls back to a freshly generated UUID if the cookie is
|
| 229 |
# not yet readable (first visit, or before the JS component has initialised).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
# ---------------------------------------------------------------------------
|
| 231 |
-
|
| 232 |
-
def _get_cookie_manager() -> stx.CookieManager:
|
| 233 |
-
"""Return a singleton CookieManager (cached across reruns)."""
|
| 234 |
-
return stx.CookieManager(key="kuda_cookie_manager")
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
_cookie_manager = _get_cookie_manager()
|
| 238 |
_cookies = _cookie_manager.get_all()
|
| 239 |
|
| 240 |
# CookieManager loads cookies asynchronously via a JS component. On the very
|
|
|
|
| 227 |
# Per-browser session ID — persisted in a cookie so chat history survives
|
| 228 |
# page refreshes. Falls back to a freshly generated UUID if the cookie is
|
| 229 |
# not yet readable (first visit, or before the JS component has initialised).
|
| 230 |
+
#
|
| 231 |
+
# CookieManager must be instantiated directly on every rerun (it cannot be
|
| 232 |
+
# wrapped in @st.cache_resource because its constructor calls a widget
|
| 233 |
+
# command). Streamlit treats it as the same widget across reruns thanks to
|
| 234 |
+
# the stable `key` argument.
|
| 235 |
# ---------------------------------------------------------------------------
|
| 236 |
+
_cookie_manager = stx.CookieManager(key="kuda_cookie_manager")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
_cookies = _cookie_manager.get_all()
|
| 238 |
|
| 239 |
# CookieManager loads cookies asynchronously via a JS component. On the very
|