chore(streamlit): migrate components.v1.html → st.iframe (deprecation)
Streamlit logs a deprecation notice on every render: Please replace ``st.components.v1.html`` with ``st.iframe``. ``st.components.v1.html`` will be removed after 2026-06-01. Replace all 9 call sites (6 tool pages + 3 in ``_legacy.py``). Both APIs feed ``srcdoc`` to the underlying iframe so the HTML/JS payload and the cross-frame DOM access pattern (``window.parent.document``) are unchanged. ``st.iframe`` rejects ``height=0`` (raises ``StreamlitInvalid HeightError``), so bump every zero-height call to ``height=1``. 1px is effectively invisible — these are script-only iframes, no visible payload — and avoids the validator. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -781,8 +781,7 @@ a[data-testid="stPageLink"][href$="/close/"] {
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
from streamlit.components.v1 import html as _components_html
|
||||
_components_html(
|
||||
st.iframe(
|
||||
f"""
|
||||
<script>
|
||||
(function () {{
|
||||
@@ -861,7 +860,7 @@ a[data-testid="stPageLink"][href$="/close/"] {
|
||||
}})();
|
||||
</script>
|
||||
""",
|
||||
height=0,
|
||||
height=1,
|
||||
)
|
||||
|
||||
|
||||
@@ -881,7 +880,7 @@ def _render_sticky_footer_DISABLED() -> None:
|
||||
1. ``st.markdown`` injects the CSS rules into the parent document.
|
||||
Class-targeted, so the rules apply once the footer DOM node
|
||||
exists regardless of where it lives.
|
||||
2. ``streamlit.components.v1.html`` renders a zero-height iframe
|
||||
2. ``st.iframe`` renders a zero-height iframe
|
||||
whose JS reaches ``window.parent.document`` and creates / moves
|
||||
a ``#datatools-sticky-footer`` div directly under ``<body>``.
|
||||
This bypasses every Streamlit container.
|
||||
@@ -951,8 +950,7 @@ def _render_sticky_footer_DISABLED() -> None:
|
||||
# reachable; if a sandbox config ever blocks that we fall back to
|
||||
# rendering inside the iframe itself (still visible, just sized
|
||||
# to the iframe rather than the viewport).
|
||||
from streamlit.components.v1 import html as _components_html
|
||||
_components_html(
|
||||
st.iframe(
|
||||
f"""
|
||||
<script>
|
||||
(function () {{
|
||||
@@ -987,7 +985,7 @@ def _render_sticky_footer_DISABLED() -> None:
|
||||
}})();
|
||||
</script>
|
||||
""",
|
||||
height=0,
|
||||
height=1,
|
||||
)
|
||||
|
||||
|
||||
@@ -1058,8 +1056,7 @@ def shutdown_app() -> None:
|
||||
|
||||
threading.Thread(target=_hard_exit, daemon=True).start()
|
||||
|
||||
from streamlit.components.v1 import html as _components_html
|
||||
_components_html(_farewell_script(), height=0)
|
||||
st.iframe(_farewell_script(), height=1)
|
||||
st.success(_t("quit.shutting_down"))
|
||||
st.stop()
|
||||
|
||||
|
||||
@@ -414,8 +414,7 @@ else:
|
||||
# triggered by unrelated widgets in the Results section don't yank the
|
||||
# viewport back to the top of Results.
|
||||
if st.session_state.pop("_dedup_scroll_to_results", False):
|
||||
from streamlit.components.v1 import html as _components_html
|
||||
_components_html(
|
||||
st.iframe(
|
||||
"""
|
||||
<script>
|
||||
const doc = window.parent.document;
|
||||
@@ -423,5 +422,5 @@ if st.session_state.pop("_dedup_scroll_to_results", False):
|
||||
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||
</script>
|
||||
""",
|
||||
height=0,
|
||||
height=1,
|
||||
)
|
||||
|
||||
@@ -400,8 +400,7 @@ with dl_c:
|
||||
# unrelated widgets in the Results section (e.g., the Show-hidden
|
||||
# toggle) don't yank the viewport back to the top of Results.
|
||||
if st.session_state.pop("_textclean_scroll_to_results", False):
|
||||
from streamlit.components.v1 import html as _components_html
|
||||
_components_html(
|
||||
st.iframe(
|
||||
"""
|
||||
<script>
|
||||
const doc = window.parent.document;
|
||||
@@ -409,5 +408,5 @@ if st.session_state.pop("_textclean_scroll_to_results", False):
|
||||
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||
</script>
|
||||
""",
|
||||
height=0,
|
||||
height=1,
|
||||
)
|
||||
|
||||
@@ -670,8 +670,7 @@ with dl_c:
|
||||
# unrelated widgets in the Results section don't yank the viewport back
|
||||
# to the top of Results.
|
||||
if st.session_state.pop("_fmtstd_scroll_to_results", False):
|
||||
from streamlit.components.v1 import html as _components_html
|
||||
_components_html(
|
||||
st.iframe(
|
||||
"""
|
||||
<script>
|
||||
const doc = window.parent.document;
|
||||
@@ -679,5 +678,5 @@ if st.session_state.pop("_fmtstd_scroll_to_results", False):
|
||||
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||
</script>
|
||||
""",
|
||||
height=0,
|
||||
height=1,
|
||||
)
|
||||
|
||||
@@ -433,8 +433,7 @@ with dl_c:
|
||||
# unrelated widgets in the Results section don't yank the viewport
|
||||
# back to the top of Results.
|
||||
if st.session_state.pop("_missing_scroll_to_results", False):
|
||||
from streamlit.components.v1 import html as _components_html
|
||||
_components_html(
|
||||
st.iframe(
|
||||
"""
|
||||
<script>
|
||||
const doc = window.parent.document;
|
||||
@@ -442,5 +441,5 @@ if st.session_state.pop("_missing_scroll_to_results", False):
|
||||
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||
</script>
|
||||
""",
|
||||
height=0,
|
||||
height=1,
|
||||
)
|
||||
|
||||
@@ -476,8 +476,7 @@ with dl_c:
|
||||
# unrelated widgets in the Results section don't yank the viewport back
|
||||
# to the top of Results.
|
||||
if st.session_state.pop("_colmap_scroll_to_results", False):
|
||||
from streamlit.components.v1 import html as _components_html
|
||||
_components_html(
|
||||
st.iframe(
|
||||
"""
|
||||
<script>
|
||||
const doc = window.parent.document;
|
||||
@@ -485,5 +484,5 @@ if st.session_state.pop("_colmap_scroll_to_results", False):
|
||||
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||
</script>
|
||||
""",
|
||||
height=0,
|
||||
height=1,
|
||||
)
|
||||
|
||||
@@ -434,8 +434,7 @@ with dl_c:
|
||||
# unrelated widgets in the Results section don't yank the viewport
|
||||
# back to the top of Results.
|
||||
if st.session_state.pop("_pipeline_scroll_to_results", False):
|
||||
from streamlit.components.v1 import html as _components_html
|
||||
_components_html(
|
||||
st.iframe(
|
||||
"""
|
||||
<script>
|
||||
const doc = window.parent.document;
|
||||
@@ -443,5 +442,5 @@ if st.session_state.pop("_pipeline_scroll_to_results", False):
|
||||
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||
</script>
|
||||
""",
|
||||
height=0,
|
||||
height=1,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user