[feature] Add autoscroll parameter to st.container#14502
[feature] Add autoscroll parameter to st.container#14502lukasmasuch merged 2 commits intodevelopfrom
autoscroll parameter to st.container#14502Conversation
Add an `autoscroll: bool | None = None` parameter to `st.container()` that allows users to explicitly control the scroll-to-bottom behavior for fixed-height containers. - `autoscroll=True`: Force enable auto-scroll for any content - `autoscroll=False`: Force disable auto-scroll even with chat messages - `autoscroll=None` (default): Preserve existing behavior Closes #8836 Co-Authored-By: Claude Opus 4.6 <[email protected]>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
There was a problem hiding this comment.
Summary
This PR adds an autoscroll: bool | None = None parameter to st.container(), giving users explicit control over scroll-to-bottom behavior in fixed-height containers. The implementation spans all layers: a new optional bool autoscroll = 16 protobuf field in Block.proto, backend parameter handling in layouts.py, updated frontend logic in shouldActivateScrollToBottom(), and comprehensive tests (Python unit, frontend unit, and E2E). The default (None) preserves existing behavior — auto-scroll only activates when chat messages are present.
All three reviewers (claude-4.6-opus-high-thinking, gemini-3.1-pro, gpt-5.3-codex-high) completed their reviews successfully.
Code Quality
Consensus: Clean and well-structured. All three reviewers agreed the implementation is cleanly scoped and follows existing Streamlit patterns.
Specific strengths noted across reviews:
- The
autoscrollparameter is correctly keyword-only with aNonedefault. - The protobuf field uses the correct next available ID (16) and the "Next ID" comment is properly updated from the stale value of 14 to 17.
- The frontend refactor of
shouldActivateScrollToBottom()improves readability with an early return for the no-pixel-height case, and correctly handlesnull/undefinedfor protobuf optional field semantics. - The backend only sets the proto field when explicitly provided (
if autoscroll is not None), preserving clean wire format.
One documentation issue identified (unanimous across all reviewers): the RST substitution |st.chat_message|_ in the docstring is missing its corresponding replacement definition. See inline comment for details.
Test Coverage
Consensus: Solid and adequate. All reviewers agreed the test coverage is comprehensive across all three layers:
- Python unit tests (3 tests): Cover
autoscroll=True,autoscroll=False, andautoscroll=None(default), including proto field presence/absence checks and the without-height edge case. - Frontend unit tests (5 parameterized cases): Cover all combinations of autoscroll values (
true/false/null) with and without fixed height, with and without chat children. - E2E tests: Verify
data-test-scroll-behaviorattribute for bothautoscroll=True(without chat messages) andautoscroll=False(with chat messages), using key-based locators andexpectassertions.
One reviewer (gpt-5.3-codex-high) optionally suggested adding a public API typing test in lib/tests/streamlit/typing/ for the new autoscroll parameter. This is a nice-to-have for guarding future typing regressions but is not blocking.
Backwards Compatibility
Consensus: Fully backwards compatible. All reviewers unanimously agreed:
autoscroll=None(default) preserves existing behavior identically.- The protobuf field is
optional, so older frontends simply ignore it. - No existing API signatures are changed; the new parameter is keyword-only.
Security & Risk
Consensus: No concerns. All reviewers agreed this is a low-risk, purely cosmetic/UX change. No authentication, routing, WebSocket, file handling, CORS, or security header changes are involved.
External test recommendation
- Recommend external_test: No
- Triggered categories: None
- Evidence:
- Changes are limited to a new optional protobuf field, a Python parameter, and frontend scroll behavior logic.
- No routing, auth, WebSocket, embedding, asset serving, CORS, storage, or security header changes.
- Suggested external_test focus areas: N/A
- Confidence: High (unanimous across all reviewers)
- Assumptions and gaps: None. The change is self-contained in the container rendering path.
Accessibility
Consensus: No concerns. The autoscroll parameter affects scroll position behavior only and does not introduce new interactive controls, keyboard flows, or ARIA semantics. The existing useScrollToBottom hook already handles user intent (pausing auto-scroll on manual scroll-up).
Recommendations
- Fix the missing RST substitution definition for
|st.chat_message|_in theautoscrollparameter docstring inlib/streamlit/elements/layouts.py. Add the.. |st.chat_message| replace::and.. _st.chat_message:directives after the parameter description. (Raised by all three reviewers.) - Optional: Add a public API typing test covering
LayoutsMixin().container(autoscroll=...)inlib/tests/streamlit/typing/to guard future typing regressions. (Suggested by gpt-5.3-codex-high.)
Verdict
APPROVED: Well-implemented feature with clean code, comprehensive tests, full backwards compatibility, and unanimous approval from all three reviewers. One documentation fix (missing RST substitution) should be addressed before merge but is not blocking.
Consolidated AI review by claude-4.6-opus-high-thinking, synthesizing reviews from claude-4.6-opus-high-thinking, gemini-3.1-pro, and gpt-5.3-codex-high.
This review also includes 1 inline comment(s) on specific code lines.
There was a problem hiding this comment.
Pull request overview
Adds an autoscroll: bool | None = None parameter to st.container() to let users explicitly enable/disable the “scroll to bottom” behavior for fixed-height containers, while preserving the existing default behavior when unset.
Changes:
- Adds
optional bool autoscrollto theBlockprotobuf. - Plumbs the new
autoscrollparameter through the Python backendst.container()API into the block proto. - Updates frontend scroll-activation logic + unit/E2E coverage for explicit autoscroll settings.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| proto/streamlit/proto/Block.proto | Adds autoscroll field to the Block message to transport the setting to the frontend. |
| lib/streamlit/elements/layouts.py | Adds autoscroll parameter to st.container() and serializes it into the block proto when explicitly set. |
| lib/tests/streamlit/elements/layouts_test.py | Adds unit tests validating proto serialization behavior for autoscroll. |
| frontend/lib/src/components/core/Block/utils.ts | Updates shouldActivateScrollToBottom to respect explicit autoscroll when present. |
| frontend/lib/src/components/core/Block/utils.test.ts | Adds parameterized tests covering explicit autoscroll scenarios and defaults. |
| e2e_playwright/st_container.py | Adds app script cases to exercise explicit autoscroll=True/False. |
| e2e_playwright/st_container_test.py | Adds an E2E test asserting the rendered scroll behavior attribute for explicit autoscroll. |
- Add RST substitution definition for st.chat_message in docstring - Add HasField assertion in test to verify proto field presence for explicit False Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Summary
This PR adds an autoscroll parameter (bool | None = None) to st.container(), giving users explicit control over scroll-to-bottom behavior in fixed-height containers. Previously, auto-scroll was hard-coded to activate only when a container had both a fixed pixel height and st.chat_message children. Now:
autoscroll=Trueforces auto-scroll for any fixed-height container.autoscroll=Falsedisables auto-scroll even when chat messages are present.autoscroll=None(default) preserves existing behavior.
Changes span all layers: protobuf (Block.proto), Python backend (layouts.py), frontend logic (utils.ts), with coverage from Python unit tests, frontend unit tests, and E2E Playwright tests.
Reviewer consensus: 3/3 reviewers (claude-4.6-opus-high-thinking, gemini-3.1-pro, gpt-5.3-codex-high) approved this PR unanimously. No critical or blocking issues were raised.
Code Quality
All three reviewers agreed the implementation is clean, minimal, and follows existing Streamlit codebase patterns:
- Protobuf: The new
optional bool autoscroll = 16field onBlockis correctly placed. The "Next ID" comment is properly updated. - Backend: The Python code correctly uses protobuf optionality — only setting the field when
autoscroll is not None, so the default case sends no value over the wire. - Frontend: The
shouldActivateScrollToBottomrefactor cleanly handles the precedence of the explicitautoscrollsetting over the implicit chat message check. Theautoscroll !== null && autoscroll !== undefinedguard properly handles protobuf optionality semantics. - Docstring: Parameter documentation follows the existing NumPy-style convention with proper RST cross-references.
No maintainability concerns were identified by any reviewer.
Test Coverage
All reviewers confirmed adequate test coverage across all layers:
- Python unit tests (
layouts_test.py): 3 test cases coveringTrue/FalsewithHasFieldassertion,Nonenot setting the field, andautoscroll=Truewithout height. Tests use@parameterized.expandconsistent with the class-basedunittest.TestCasepattern. - Frontend unit tests (
utils.test.ts): 5 parameterized test cases covering all meaningful combinations — explicit true/false with and without fixed height, and null fallback to default behavior with and without chat messages. - E2E tests (
st_container_test.py): Tests bothautoscroll=True(verifyingdata-test-scroll-behavior="scroll-to-bottom") andautoscroll=Falsewith chat messages (verifyingdata-test-scroll-behavior="normal"). Uses key-based locators per best practices.
Backwards Compatibility
All three reviewers unanimously confirmed full backwards compatibility:
- The parameter defaults to
None, preserving existing behavior. - The protobuf field is
optional, so older frontends that don't understand it will simply ignore it. - No existing APIs are changed; this is purely additive.
Security & Risk
All reviewers agreed there are no security concerns. The change does not touch WebSocket handling, authentication, session management, file serving, HTML/Markdown rendering, or any other security-sensitive area. The autoscroll field is a simple boolean controlling scroll behavior — no code execution risk.
External test recommendation
- Recommend external_test: No
- Triggered categories: None
- Evidence:
proto/streamlit/proto/Block.proto: Adds a simpleoptional boolfield — no routing, auth, or transport changes.frontend/lib/src/components/core/Block/utils.ts: Pure UI logic change — scroll behavior only.lib/streamlit/elements/layouts.py: Adds optional API parameter — no server, WebSocket, or security-related changes.
- Suggested external_test focus areas: None
- Confidence: High (unanimous across all three reviewers)
- Assumptions and gaps: None — the change is entirely local to container scroll behavior with no network, auth, embedding, or cross-origin impact.
Accessibility
No accessibility concerns. All reviewers agreed the change only affects auto-scroll behavior and does not introduce new interactive elements, alter DOM structure, or impact assistive technology. The data-test-scroll-behavior attribute is test-only and does not affect screen readers or keyboard navigation.
Recommendations
- (Minor, non-blocking) Consider adding a typing test in
lib/tests/streamlit/typing/forst.container()to verify theautoscrollparameter type (bool | None). Other layout commands (expander, tabs, popover) have typing tests, and this is a new public API parameter. (Raised by claude-4.6-opus-high-thinking; other reviewers did not flag this.)
Verdict
APPROVED: All three reviewers unanimously approved. The PR introduces a well-scoped, clean, fully backwards-compatible feature with good test coverage across backend, frontend, and E2E layers. No critical issues, security concerns, or blocking changes were identified.
Consolidated AI review by claude-4.6-opus-high-thinking from 3 individual reviews: claude-4.6-opus-high-thinking, gemini-3.1-pro, gpt-5.3-codex-high. All expected models completed their reviews successfully.
QA Test Artifacts
|
autoscroll parameter to st.container
sfc-gh-lwilby
left a comment
There was a problem hiding this comment.
LGTM, I like the test artifacts!
Describe your changes
Add an
autoscroll: bool | None = Noneparameter tost.container()that allows users to explicitly control the scroll-to-bottom behavior for fixed-height containers.Changes:
autoscroll=True: Force enable auto-scroll for any content (not just chat messages)autoscroll=False: Force disable auto-scroll even when chat messages are presentautoscroll=None(default): Preserve existing behavior - auto-scroll only when container has chat messagesImplementation:
autoscrollparameter tost.container()inlayouts.pyoptional bool autoscrollfield toBlock.protoshouldActivateScrollToBottom()inutils.tsto check explicit autoscroll settingGitHub Issue Link (if applicable)
Testing Plan
data-test-scroll-behaviorattribute for both True and False casesContribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Agent metrics