CSS Hacks have weird behaviour (of course)

When I run this code, something weird can happen sometimes, but not always. Every reload has a chance to have the bug:

import streamlit as st

st.write("# ")

hide_streamlit_style = """
                    #MainMenu {visibility: hidden;}
                    footer {visibility: hidden;}
                    #root > div:nth-child(1) > div > div > div > div > section > div {padding-top: 2rem;}
                    #root > div:nth-child(1) > div > div > div > div > section > div > div {padding-top: 2rem;}
st.markdown(hide_streamlit_style, unsafe_allow_html=True)


the st.write line needs to be present for this bug to occur.

Refreshing the page sometimes yields this weird state with the sidebar raised (thereโ€™s whitespace at the bottom and the x is closer to the top):

and other times itโ€™s just the normal expected output:

Streamlit 1.13.0, Chrome, Win 10