Phantom Checkboxes spawn if UI layout changes while long-running cache_data query in progress

Baseline Info:

Bug description:

My app has a ‘simple’ and an ‘advanced’ mode, which are selected using a element. Switching to advanced mode will add some additional inputs and st.write elements to the UI (but will not remove any existing elements). The issue I’m finding is that if I switch back-and-forth between modes while a long running query with @st.cache_data is running, UI elements will permanently remain in the DOM but become greyed out. Even after the execution of the task is finished, the elements remain. But switching back-and-forth between the modes after execution does not cause new ‘phantom’ elements to be added to the DOM.

Here is a video demo: Loom: Bug Demo: Streamlit Phantom UI Element