Ghost double text bug

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"])
1 Like

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.

1 Like

Thank you for the support @mathcatsand. This is great and should help make the chat interface experience smoother : -)
Just upvoted :+1:

add these lines below at the end of your function.
it’s a dirty trick to clean up the shadows.

for i in range(0, 100):
      st.markdown(" ")