-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
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
I have an issue with st.fragment
s within a container disappearing on rerender. The initial render works as expected, but after the first user interaction within the fragment, the container seems to act somewhat like an st.empty()
.
It only happens under very particular conditions. I isolated the issue by simplifying my example as much as possible. Of course, that example now looks silly, but in my app, these "particular conditions" have reasons to be.
Reproducible Code Example
import streamlit as st
@st.fragment # Has to be a fragment.
def a():
st.button("Rerender `a()`")
container = st.container()
with container:
b(1)
with container: # Has to be a separate `with`.
b(2)
@st.fragment # Has to be a fragment.
def b(i: int):
st.markdown(i)
a()
Steps To Reproduce
- Try the above code example.
- On the initial render, you should see "1" and "2".
- Click the "Rerender
a()
" button. - Notice the "1" is now gone.
- Variations:
- If you add anything after
with container: b(2)
, saycontainer.markdown(3)
, the "2" will also disappear, leaving only the "3". - If you replace
st.container()
withst.columns(1)[0]
,st.expander("")
,st.popover("")
, orst.tabs(("Tab",))[0]
, the same issue happens.
- If you add anything after
- If you remove any one of the three lines with a comment, it avoids the issue. These three conditions are necessary to reproduce the issue.
Expected Behavior
Always seeing "1" and "2", even after a rerender.
Current Behavior
Initial render:
After clicking the "Rerender a()
" button:
Is this a regression?
- Yes, this used to work in a previous version.
Debug info
- Streamlit version: 1.49.1
- Python version: 3.11.9
- Operating System: MacOS
- Browser: Chrome
Additional Information
See Steps To Reproduce
#7 for workarounds. Personally, I am not blocked; I am fine with the second workaround. I just thought I'd share my findings since it took me a whiiile to identify the issue, and it's clearly unexpected.