I’m asking an engineer, but to me, the behavior in 1.32.0 actually seems like a bug that was fixed. If I use a container instead of st.chat_message the stale elements are handled the same in 1.32.0 and 1.33.0 (which is consitent with the current behavior).
If I run this code in 1.32.0 and 1.33.0, I see stale elements in both when using st.container. However, I only see stale elements in 1.33.0 when I use st.chat_message("ai").
import streamlit as st
import time
if "history" not in st.session_state:
st.session_state.history = []
add = st.button("Add")
for item in st.session_state.history:
# with st.chat_message("user"):
with st.container(border=True):
item[0]
item[1]
if add:
# with st.chat_message("user"):
with st.container(border=True):
with st.spinner("Responding"):
time.sleep(1)
"First"
time.sleep(1)
"Second"
st.session_state.history.append(["First","Second"])
I’ve learned that there was a hacky attempt to disable stale elements within st.chat_message specifically, but it did not work long term and could not be sustained. Hence, the behavior reverted to the long-existing, current standard.
I’ve put in a feature request for a utility command that can mark the end of containers and thus provide a way for developers to declare the point at which they want to clear stale elements. (Streamlit has no way of knowing ahead of time when the code is done writing to a container, which is why stale elements are currently cleared at the end of the script run.)
If you’d like such a feature, feel free to upvote it and leave further comments.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.