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:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from streamlit.components.v1 import html as _components_html
|
st.iframe(
|
||||||
_components_html(
|
|
||||||
f"""
|
f"""
|
||||||
<script>
|
<script>
|
||||||
(function () {{
|
(function () {{
|
||||||
@@ -861,7 +860,7 @@ a[data-testid="stPageLink"][href$="/close/"] {
|
|||||||
}})();
|
}})();
|
||||||
</script>
|
</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.
|
1. ``st.markdown`` injects the CSS rules into the parent document.
|
||||||
Class-targeted, so the rules apply once the footer DOM node
|
Class-targeted, so the rules apply once the footer DOM node
|
||||||
exists regardless of where it lives.
|
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
|
whose JS reaches ``window.parent.document`` and creates / moves
|
||||||
a ``#datatools-sticky-footer`` div directly under ``<body>``.
|
a ``#datatools-sticky-footer`` div directly under ``<body>``.
|
||||||
This bypasses every Streamlit container.
|
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
|
# reachable; if a sandbox config ever blocks that we fall back to
|
||||||
# rendering inside the iframe itself (still visible, just sized
|
# rendering inside the iframe itself (still visible, just sized
|
||||||
# to the iframe rather than the viewport).
|
# to the iframe rather than the viewport).
|
||||||
from streamlit.components.v1 import html as _components_html
|
st.iframe(
|
||||||
_components_html(
|
|
||||||
f"""
|
f"""
|
||||||
<script>
|
<script>
|
||||||
(function () {{
|
(function () {{
|
||||||
@@ -987,7 +985,7 @@ def _render_sticky_footer_DISABLED() -> None:
|
|||||||
}})();
|
}})();
|
||||||
</script>
|
</script>
|
||||||
""",
|
""",
|
||||||
height=0,
|
height=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1058,8 +1056,7 @@ def shutdown_app() -> None:
|
|||||||
|
|
||||||
threading.Thread(target=_hard_exit, daemon=True).start()
|
threading.Thread(target=_hard_exit, daemon=True).start()
|
||||||
|
|
||||||
from streamlit.components.v1 import html as _components_html
|
st.iframe(_farewell_script(), height=1)
|
||||||
_components_html(_farewell_script(), height=0)
|
|
||||||
st.success(_t("quit.shutting_down"))
|
st.success(_t("quit.shutting_down"))
|
||||||
st.stop()
|
st.stop()
|
||||||
|
|
||||||
|
|||||||
@@ -414,8 +414,7 @@ else:
|
|||||||
# triggered by unrelated widgets in the Results section don't yank the
|
# triggered by unrelated widgets in the Results section don't yank the
|
||||||
# viewport back to the top of Results.
|
# viewport back to the top of Results.
|
||||||
if st.session_state.pop("_dedup_scroll_to_results", False):
|
if st.session_state.pop("_dedup_scroll_to_results", False):
|
||||||
from streamlit.components.v1 import html as _components_html
|
st.iframe(
|
||||||
_components_html(
|
|
||||||
"""
|
"""
|
||||||
<script>
|
<script>
|
||||||
const doc = window.parent.document;
|
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'});
|
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||||
</script>
|
</script>
|
||||||
""",
|
""",
|
||||||
height=0,
|
height=1,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -400,8 +400,7 @@ with dl_c:
|
|||||||
# unrelated widgets in the Results section (e.g., the Show-hidden
|
# unrelated widgets in the Results section (e.g., the Show-hidden
|
||||||
# toggle) don't yank the viewport back to the top of Results.
|
# toggle) don't yank the viewport back to the top of Results.
|
||||||
if st.session_state.pop("_textclean_scroll_to_results", False):
|
if st.session_state.pop("_textclean_scroll_to_results", False):
|
||||||
from streamlit.components.v1 import html as _components_html
|
st.iframe(
|
||||||
_components_html(
|
|
||||||
"""
|
"""
|
||||||
<script>
|
<script>
|
||||||
const doc = window.parent.document;
|
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'});
|
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||||
</script>
|
</script>
|
||||||
""",
|
""",
|
||||||
height=0,
|
height=1,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -670,8 +670,7 @@ with dl_c:
|
|||||||
# unrelated widgets in the Results section don't yank the viewport back
|
# unrelated widgets in the Results section don't yank the viewport back
|
||||||
# to the top of Results.
|
# to the top of Results.
|
||||||
if st.session_state.pop("_fmtstd_scroll_to_results", False):
|
if st.session_state.pop("_fmtstd_scroll_to_results", False):
|
||||||
from streamlit.components.v1 import html as _components_html
|
st.iframe(
|
||||||
_components_html(
|
|
||||||
"""
|
"""
|
||||||
<script>
|
<script>
|
||||||
const doc = window.parent.document;
|
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'});
|
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||||
</script>
|
</script>
|
||||||
""",
|
""",
|
||||||
height=0,
|
height=1,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -433,8 +433,7 @@ with dl_c:
|
|||||||
# unrelated widgets in the Results section don't yank the viewport
|
# unrelated widgets in the Results section don't yank the viewport
|
||||||
# back to the top of Results.
|
# back to the top of Results.
|
||||||
if st.session_state.pop("_missing_scroll_to_results", False):
|
if st.session_state.pop("_missing_scroll_to_results", False):
|
||||||
from streamlit.components.v1 import html as _components_html
|
st.iframe(
|
||||||
_components_html(
|
|
||||||
"""
|
"""
|
||||||
<script>
|
<script>
|
||||||
const doc = window.parent.document;
|
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'});
|
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||||
</script>
|
</script>
|
||||||
""",
|
""",
|
||||||
height=0,
|
height=1,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -476,8 +476,7 @@ with dl_c:
|
|||||||
# unrelated widgets in the Results section don't yank the viewport back
|
# unrelated widgets in the Results section don't yank the viewport back
|
||||||
# to the top of Results.
|
# to the top of Results.
|
||||||
if st.session_state.pop("_colmap_scroll_to_results", False):
|
if st.session_state.pop("_colmap_scroll_to_results", False):
|
||||||
from streamlit.components.v1 import html as _components_html
|
st.iframe(
|
||||||
_components_html(
|
|
||||||
"""
|
"""
|
||||||
<script>
|
<script>
|
||||||
const doc = window.parent.document;
|
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'});
|
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||||
</script>
|
</script>
|
||||||
""",
|
""",
|
||||||
height=0,
|
height=1,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -434,8 +434,7 @@ with dl_c:
|
|||||||
# unrelated widgets in the Results section don't yank the viewport
|
# unrelated widgets in the Results section don't yank the viewport
|
||||||
# back to the top of Results.
|
# back to the top of Results.
|
||||||
if st.session_state.pop("_pipeline_scroll_to_results", False):
|
if st.session_state.pop("_pipeline_scroll_to_results", False):
|
||||||
from streamlit.components.v1 import html as _components_html
|
st.iframe(
|
||||||
_components_html(
|
|
||||||
"""
|
"""
|
||||||
<script>
|
<script>
|
||||||
const doc = window.parent.document;
|
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'});
|
if (target) target.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||||
</script>
|
</script>
|
||||||
""",
|
""",
|
||||||
height=0,
|
height=1,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user