Rerun causes widget value to reset in python but not in browser

The value displayed in the widget and the value returned by the widget get out of sync. Is this a bug, or am I doing something wrong?

import streamlit as st

if st.button("rerun"):
    st.rerun()

value = st.selectbox("Select a value", ["A", "B", "C"], index=0)

st.write(f"Selected value: {value}")

Steps to reproduce

  1. Select C
  2. Press rerun

The widget still shows C while the actual value has been reset to A

When hitting “rerun” the script will get to the rerun() call before getting to the widget. I guess that should trigger a widget cleanup since the widget has not been rendered, unless widget cleanup does not happen when rerun is called manually. In any case, the displayed value in the select box should be the same as the value returned in the python script.

Streamlit version: 1.40.1
local run

I would expect A in both places, so I vote bug.

filed a bug: st.selectbox updates return value, but do not update widget value · Issue #10114 · streamlit/streamlit · GitHub