Issue with s.chat_message and Page not loading correctly (sometimes)


I’m developing a new page for my app that will use LangChain to interact with my Database via OpenAI - it’s working great for the most part!

However, during some submissions of the st.chat_input field and the st.chat_message, the page is acting funny… as soon as I hit submit the message I just typed will overwrite the last message that was in the thread, and you don’t see a RUNNING indicator for streamlit. If you wait a little bit and reload the page (by clicking the navigation, not refreshing) the question and answer will render property. It almost seems that as the chat starts to get towards the bottom of the page and the input control it acts funny…

Anyone have any thoughts on where to look or what might be wrong?

Video of Behavior

  1. Community Cloud:
  2. There are no error messages to share
  3. Repo and Actual File
  4. Versions:
    Python 3.11.6
    Streamlit, version 1.30.0

Note: Please don’t flag this as an advertisement - you didnt’ read this if you think that…
Edit to try to unblock :slight_smile:

1 Like

I found that this is an issue with the cookie manager used by streamlit-authenticator - i’ll keep an eye on that thread and issue:

Note: Please don’t flag this as an advertisement - you didnt’ read this if you think that…


Hello @brian-dka,

Here’s how you can manage a chat application in Streamlit using session state:

import streamlit as st

if 'chat_history' not in st.session_state:
    st.session_state.chat_history = []

for message in st.session_state.chat_history:
    st.chat_message(message['role'], message['content'])

user_input = st.chat_input("Say something...")
if user_input:
    st.session_state.chat_history.append({'role': 'user', 'content': user_input})
    response = "This is a response to your message."
    st.session_state.chat_history.append({'role': 'bot', 'content': response})

Kind Regards,
Sahir Maharaj
Data Scientist | AI Engineer

P.S. Lets connect on LinkedIn!

➤ Website:
➤ Email:
➤ Want me to build your solution? Lets chat about how I can assist!
➤ Join my Medium community of 30k readers! Sharing my knowledge about data science and AI
➤ 100+ FREE Power BI Themes: Download Now

1 Like

Thank you @sahirmaharaj ! This results in the same behaviour - looks like this is a common bug from the streamlit-authentication. The author is working on it.

1 Like

It’s my pleasure @brian-dka. Feel free to let me know if you might have any further questions!