-
Notifications
You must be signed in to change notification settings - Fork 4k
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 am noticing behaviour very similar to the behaviour described in this issue when using v1.41.1. In particular, I'm noticing that if I cause a rerun by pressing "R" and there is a cache miss, then sometimes the page reloads, element status is lost (e.g. active element, but not state like selected items) and scroll position is lost (the page is scrolled to the very top).
I first noticed this on a large page with many elements and several cached_data references. I was able to narrow it down to a single simple page show in the reproducible code.
The problem seems to come up when there are multiple cached_data functions that all expire together and all need to be run again as part of the same app rerun.
The attached video shows the reload happening consistently on the cache miss, i.e. every 3 seconds. I've found that if I reduce the number of cached_data functions, then this is less likely to happen.
Reproducible Code Example
import streamlit as st
import pandas as pd
@st.cache_data(ttl=3, show_spinner=True)
def get_table(table_name: str) -> list:
return [{"name": "AUD"}, {"name": "USD"}, {"name": "EUR"}, {"name": "GBP"}]
def get_table_as_dataframe(table_name: str) -> pd.DataFrame:
return pd.DataFrame(get_table(table_name=table_name))
currencies1 = get_table_as_dataframe("1")
currencies2 = get_table_as_dataframe("2")
currencies3 = get_table_as_dataframe("3")
currencies4 = get_table_as_dataframe("4")
currencies5 = get_table_as_dataframe("5")
currencies6 = get_table_as_dataframe("6")
currencies7 = get_table_as_dataframe("7")
currencies8 = get_table_as_dataframe("8")
currencies9 = get_table_as_dataframe("9")
currencies10 = get_table_as_dataframe("10")
currencies11 = get_table_as_dataframe("11")
currencies12 = get_table_as_dataframe("12")
currencies13 = get_table_as_dataframe("13")
currencies14 = get_table_as_dataframe("14")
currencies15 = get_table_as_dataframe("15")
st.markdown("### Top of the page")
st.table(currencies1)
st.table(currencies1)
st.table(currencies1)
st.table(currencies1)
st.table(currencies1)
st.multiselect(
"What are your favorite currencies?",
currencies1["name"],
)
st.text_input("Text")Steps To Reproduce
- Scroll to the bottom of the page
- Make a currency selection
- Hit "R" until the cache expires
- the page should reload and be scrolled to the top
- the previous selection is STILL in place, i.e. not all element state is lost
- Scroll to the bottom again
- Enter text into the text box and press "enter" until the cache expires
- the page should reload and be scrolled to the top
- the active selection of the text input IS LOST
Expected Behavior
The page should not be scrolled to the top and the active element should remain active.
Current Behavior
There is nothing in the browser console.
The following appears in the python logs
2025-01-17 01:55:30.907 DEBUG streamlit.web.server.browser_websocket_handler: Received the following back message:
rerun_script {
widget_states {
widgets {
id: "$$ID-811df22d59c27c532e48ee256fa80d39-None"
int_array_value {
data: 0
}
}
widgets {
id: "$$ID-882dd42dbbd4c338093ec615a29077f2-None"
string_value: "1111111"
}
}
page_script_hash: "397c4a328c8f95ca5967dac095deeca0"
}
2025-01-17 01:55:30.908 DEBUG streamlit.runtime.scriptrunner.script_runner: Beginning script thread
2025-01-17 01:55:30.908 DEBUG streamlit.runtime.scriptrunner.script_runner: Running script RerunData(widget_states=widgets {
id: "$$ID-811df22d59c27c532e48ee256fa80d39-None"
int_array_value {
data: 0
}
}
widgets {
id: "$$ID-882dd42dbbd4c338093ec615a29077f2-None"
string_value: "1111111"
}
, page_script_hash='397c4a328c8f95ca5967dac095deeca0')
2025-01-17 01:55:30.908 DEBUG streamlit.runtime.media_file_manager: Disconnecting files for session with ID 31855fe9-2f06-4d2d-ac09-4f726f8e571d
2025-01-17 01:55:30.908 DEBUG streamlit.runtime.media_file_manager: Sessions still active: dict_keys([])
2025-01-17 01:55:30.909 DEBUG streamlit.runtime.media_file_manager: Files: 0; Sessions with files: 0
2025-01-17 01:55:30.911 DEBUG streamlit.runtime.caching.cache_utils: Cache key: e070e0160f18db9df205936508f0591e
2025-01-17 01:55:30.911 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: e070e0160f18db9df205936508f0591e
2025-01-17 01:55:30.913 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: e070e0160f18db9df205936508f0591e
2025-01-17 01:55:30.915 DEBUG streamlit.runtime.caching.cache_utils: Cache key: 2b3e18e75707bbd9478816e21a3fdd4a
2025-01-17 01:55:30.915 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 2b3e18e75707bbd9478816e21a3fdd4a
2025-01-17 01:55:30.916 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 2b3e18e75707bbd9478816e21a3fdd4a
2025-01-17 01:55:30.917 DEBUG streamlit.runtime.caching.cache_utils: Cache key: 894c9b69f51fa13841a2dcc57ebe1e2f
2025-01-17 01:55:30.917 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 894c9b69f51fa13841a2dcc57ebe1e2f
2025-01-17 01:55:30.917 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 894c9b69f51fa13841a2dcc57ebe1e2f
2025-01-17 01:55:30.918 DEBUG streamlit.runtime.caching.cache_utils: Cache key: 33e415fced6619a2f5e91dacaf64325a
2025-01-17 01:55:30.918 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 33e415fced6619a2f5e91dacaf64325a
2025-01-17 01:55:30.919 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 33e415fced6619a2f5e91dacaf64325a
2025-01-17 01:55:30.919 DEBUG streamlit.runtime.caching.cache_utils: Cache key: a312bf67afb8375c5e54246304b9be68
2025-01-17 01:55:30.919 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: a312bf67afb8375c5e54246304b9be68
2025-01-17 01:55:30.919 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: a312bf67afb8375c5e54246304b9be68
2025-01-17 01:55:30.920 DEBUG streamlit.runtime.caching.cache_utils: Cache key: 800425b80fd72720a71947f102c81fa7
2025-01-17 01:55:30.920 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 800425b80fd72720a71947f102c81fa7
2025-01-17 01:55:30.920 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 800425b80fd72720a71947f102c81fa7
2025-01-17 01:55:30.920 DEBUG streamlit.runtime.caching.cache_utils: Cache key: df8691c87869548ae28c4d67b0ce2d83
2025-01-17 01:55:30.920 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: df8691c87869548ae28c4d67b0ce2d83
2025-01-17 01:55:30.921 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: df8691c87869548ae28c4d67b0ce2d83
2025-01-17 01:55:30.921 DEBUG streamlit.runtime.caching.cache_utils: Cache key: 7107b569f00e427014580e7313504cdb
2025-01-17 01:55:30.921 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 7107b569f00e427014580e7313504cdb
2025-01-17 01:55:30.922 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 7107b569f00e427014580e7313504cdb
2025-01-17 01:55:30.922 DEBUG streamlit.runtime.caching.cache_utils: Cache key: 3f9e6bde62be5ab0e489d70075bdaa66
2025-01-17 01:55:30.922 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 3f9e6bde62be5ab0e489d70075bdaa66
2025-01-17 01:55:30.923 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 3f9e6bde62be5ab0e489d70075bdaa66
2025-01-17 01:55:30.923 DEBUG streamlit.runtime.caching.cache_utils: Cache key: b4cb12d1434538fc9d88cd57c4b1df1b
2025-01-17 01:55:30.923 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: b4cb12d1434538fc9d88cd57c4b1df1b
2025-01-17 01:55:30.923 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: b4cb12d1434538fc9d88cd57c4b1df1b
2025-01-17 01:55:30.924 DEBUG streamlit.runtime.caching.cache_utils: Cache key: 12924a20c03721afc1c1baa93686041f
2025-01-17 01:55:30.924 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 12924a20c03721afc1c1baa93686041f
2025-01-17 01:55:30.924 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 12924a20c03721afc1c1baa93686041f
2025-01-17 01:55:30.924 DEBUG streamlit.runtime.caching.cache_utils: Cache key: 1d705635a20fe314007382c505be4d33
2025-01-17 01:55:30.924 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 1d705635a20fe314007382c505be4d33
2025-01-17 01:55:30.925 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 1d705635a20fe314007382c505be4d33
2025-01-17 01:55:30.925 DEBUG streamlit.runtime.caching.cache_utils: Cache key: 9acdbddfe3cd5c9978ada8d8672c814f
2025-01-17 01:55:30.925 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 9acdbddfe3cd5c9978ada8d8672c814f
2025-01-17 01:55:30.926 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 9acdbddfe3cd5c9978ada8d8672c814f
2025-01-17 01:55:30.926 DEBUG streamlit.runtime.caching.cache_utils: Cache key: 9f30edaed642107dec187dba84761bd0
2025-01-17 01:55:30.926 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 9f30edaed642107dec187dba84761bd0
2025-01-17 01:55:30.927 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 9f30edaed642107dec187dba84761bd0
2025-01-17 01:55:30.927 DEBUG streamlit.runtime.caching.cache_utils: Cache key: 0ad19e637e4a0d0899835e9b1f55ed1b
2025-01-17 01:55:30.927 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 0ad19e637e4a0d0899835e9b1f55ed1b
2025-01-17 01:55:30.928 DEBUG streamlit.runtime.caching.storage.in_memory_cache_storage_wrapper: Memory cache MISS: 0ad19e637e4a0d0899835e9b1f55ed1b
2025-01-17 01:55:30.933 DEBUG streamlit.runtime.media_file_manager: Removing orphaned files...
2025-01-17 01:55:30.980 DEBUG streamlit.runtime.runtime: Script run finished successfully; removing expired entries from MessageCache (max_age=2)
Is this a regression?
- Yes, this used to work in a previous version.
Debug info
- Streamlit version: 1.41.1
- Python version: 3.12
- Operating System: Linux 6.6.65-1-MANJARO
- Browser: Chromium, Firefox