AgGrid remounting on page rerun

AgGrid table is remounting when components are added before it.

Snipped to recreate the issue:

import uuid
from datetime import datetime

import pandas as pd
import streamlit as st
from st_aggrid import AgGrid, GridOptionsBuilder, JsCode

st.write(f"Last run: {}")

if st.button("This will recreate table (most of the time)"):
    st.write({"some text": "more text"})
    st.write({"some text": "more text"})
    st.write({"some text": "more text"})

if st.button("This won't recreate table (usually)"):

def data():
    return pd.DataFrame(
            {"group": "A", "index": uuid.uuid4().hex, "n": 3},
            {"group": "A", "index": uuid.uuid4().hex, "n": 1},
            {"group": "B", "index": uuid.uuid4().hex, "n": 3},

grid = GridOptionsBuilder.from_dataframe(data())
grid.configure_default_column(groupable=True, value=True, enableRowGroup=True, aggFunc="sum")
grid.configure_grid_options(getRowId=JsCode("function (params) { return; }"))
grid.configure_column("group", rowGroup=True, hide=True)

AgGrid(data(), reload_data=True, allow_unsafe_jscode=True, key="grid",, height=500)

if st.button("This won't recreate table"):
    st.write({"some text": "more text"})
    st.write({"some text": "more text"})
    st.write({"some text": "more text"})

When clicking on the first button, a few divs are added and it triggers AgGrid reload which can be seen as it takes some time to load.
(You can also verify it is reloading as any change to a table like sorting it by some column will be lost)

Clicking on the second button which adds only one div in most cases doesn’t trigger the remount.
Same for the to button that will create divs after the table.

Is there a way to force Streamlit to keep the same component instead of remounting?

It is potentially similar to the issue described here: Components keep refreshing/remounting when in a column · Issue #2145 · streamlit/streamlit · GitHub and

Python version: 3.10.8
OS: Windows 10