Clearing cache on a single method screws up multiselect selected items

I have a function like this:

@st.cache_data
def load_account_data(directory_path: str) -> pd.DataFrame:

…and a multiselect:

selected_types = st.sidebar.multiselect(
    "Account Types",
    all_types,
    default=all_types,
)

I have a button to clear the account data cache, in the case of files on disk changing:

with st.sidebar:
    if st.button("🔄 Reload Data", help="Reload all files from disk"):
        load_account_data.clear()
        st.success("Cache cleared! Data will be reloaded.")
        st.rerun()

…but when I click this button, while it clears the cached function data, it also seems to totally screw up multiselect selections: they aren’t applied, but the multiselect element renders as if they were. To fix things, I have to remove and then re-add the selections.

I’m using streamlit v1.48.1. What am I doing wrong?

I think this is a bug, so opened Multiselect Visual State vs Returned Value Mismatch · Issue #12305 · streamlit/streamlit · GitHub.

I wonder if Multipage with multiselect default and session state might be related too?