#7862·streamlit

Inputs are not saved in `st.session_state` when blocking happens

Author: WattyyyCreated Dec 20, 2023Updated Sep 16, 2026
Labelstype:bugstatus:confirmedpriority:P3feature:st.session_statefeature:callbacksstatus:needs-product-approval

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

If blocking (e.g., HTTP request, sleep) happens after the button click, user inputs on st.text_area are not saved on st.session_state. Also, if the blocking function is commented out, inputs on st.text_area are saved on st.session_state after the button click.

Reproducible Code Example

Open in Streamlit Cloud

python
import time

import streamlit as st


def set_state(i: int, text: str):
    st.session_state.stage = i
    st.session_state.lines = text.splitlines()


time.sleep(2)
if "stage" not in st.session_state:
    st.session_state.stage = 0
if st.session_state.stage == 0:
    text = st.text_area("Input your text", height=100)
    st.button(
        "Begin",
        on_click=set_state,
        args=[1, text],
    )
if st.session_state.stage == 1:
    st.title("Your text")
    for i, line in enumerate(st.session_state.lines):
        st.write(f"{i}. {line}")

Steps To Reproduce

  1. Input some text on text area
  2. Click Begin button
  3. Only the title is displayed(contents of st.session_state are not shown)

Screen Recording 2023-12-22 at 2 25 05

Expected Behavior

Inputs are saved on st.session_state and shown after the button click.

Current Behavior

User inputs are not saved in st.session_state when the button is clicked directly. However, if the user clicks somewhere other than the button or text area before clicking the button (which causes blocking), the input is saved as expected.

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version:
    • 1.29.0
  • Python version:
    • 3.11.6
  • Operating System:
    • Ubuntu 22.04.2 LTS
  • Browser:
    • Google Chrome

Additional Information

No response