Skip to content

Commit 4669594

Browse files
committed
fix(stapp): fall back to st.rerun() when fragment scope rerun is unavailable
Issue #564 reports a StreamlitAPIException on startup when the LLM selectbox in the sidebar detects a stale selected_idx (e.g. from a prior session_state). The handler calls st.rerun(scope="fragment"), which is only legal during a fragment rerun — on the initial script run it raises: StreamlitAPIException: scope="fragment" can only be specified from @st.fragment-decorated functions during fragment reruns. Wrap the call so that on the initial run (or any context where fragment rerun is unavailable) we fall back to a full st.rerun() instead of crashing.
1 parent c85b59e commit 4669594

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

frontends/stapp.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ def render_sidebar():
8484
st.caption(f"LLM Core: {llm_labels.get(current_idx, str(current_idx))}")
8585
selected_idx = st.selectbox("LLM", [idx for idx, _, _ in llm_options], index=next((i for i, (idx, _, _) in enumerate(llm_options) if idx == current_idx), 0), format_func=llm_labels.get, label_visibility="collapsed", key="sidebar_llm_select")
8686
if selected_idx != current_idx:
87-
agent.next_llm(selected_idx); st.rerun(scope="fragment")
87+
agent.next_llm(selected_idx)
88+
try:
89+
st.rerun(scope="fragment")
90+
except st.StreamlitAPIException:
91+
st.rerun()
8892
if st.button(T('force_stop')):
8993
agent.abort(); st.toast("Stop signal sended"); st.rerun()
9094
if st.button(T('desktop_pet')):

0 commit comments

Comments
 (0)