Skip to content

[feature] Add autoscroll parameter to st.container#14502

Merged
lukasmasuch merged 2 commits intodevelopfrom
lukasmasuch/container-autoscroll
Mar 26, 2026
Merged

[feature] Add autoscroll parameter to st.container#14502
lukasmasuch merged 2 commits intodevelopfrom
lukasmasuch/container-autoscroll

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Mar 24, 2026

Describe your changes

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.

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 present
  • autoscroll=None (default): Preserve existing behavior - auto-scroll only when container has chat messages

Implementation:

  • Backend: Added autoscroll parameter to st.container() in layouts.py
  • Protobuf: Added optional bool autoscroll field to Block.proto
  • Frontend: Updated shouldActivateScrollToBottom() in utils.ts to check explicit autoscroll setting

GitHub Issue Link (if applicable)

Testing Plan

  • Python Unit Tests - Tests proto field serialization for True/False/None
  • Frontend Unit Tests - Parameterized tests for all autoscroll scenarios
  • E2E Tests - Tests data-test-scroll-behavior attribute for both True and False cases

Contribution 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
Type Name Count
skill finalizing-pr 1
skill implementing-feature 1
subagent fixing-pr 1
subagent general-purpose 1
subagent qa-testing-feature 1
subagent reviewing-local-changes 1
subagent simplifying-local-changes 1

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]>
@lukasmasuch lukasmasuch added change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Mar 24, 2026
Copilot AI review requested due to automatic review settings March 24, 2026 21:02
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Mar 24, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 24, 2026

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-14502/streamlit-1.55.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-14502.streamlit.app (☁️ Deploy here if not accessible)

@lukasmasuch lukasmasuch added the ai-review If applied to PR or issue will run AI review workflow label Mar 24, 2026
@github-actions github-actions bot removed the ai-review If applied to PR or issue will run AI review workflow label Mar 24, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 autoscroll parameter is correctly keyword-only with a None default.
  • 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 handles null/undefined for 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, and autoscroll=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-behavior attribute for both autoscroll=True (without chat messages) and autoscroll=False (with chat messages), using key-based locators and expect assertions.

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

  1. Fix the missing RST substitution definition for |st.chat_message|_ in the autoscroll parameter docstring in lib/streamlit/elements/layouts.py. Add the .. |st.chat_message| replace:: and .. _st.chat_message: directives after the parameter description. (Raised by all three reviewers.)
  2. Optional: Add a public API typing test covering LayoutsMixin().container(autoscroll=...) in lib/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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 autoscroll to the Block protobuf.
  • Plumbs the new autoscroll parameter through the Python backend st.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]>
@lukasmasuch lukasmasuch added the ai-review If applied to PR or issue will run AI review workflow label Mar 24, 2026
@github-actions github-actions bot removed the ai-review If applied to PR or issue will run AI review workflow label Mar 24, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=True forces auto-scroll for any fixed-height container.
  • autoscroll=False disables 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 = 16 field on Block is 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 shouldActivateScrollToBottom refactor cleanly handles the precedence of the explicit autoscroll setting over the implicit chat message check. The autoscroll !== null && autoscroll !== undefined guard 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 covering True/False with HasField assertion, None not setting the field, and autoscroll=True without height. Tests use @parameterized.expand consistent with the class-based unittest.TestCase pattern.
  • 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 both autoscroll=True (verifying data-test-scroll-behavior="scroll-to-bottom") and autoscroll=False with chat messages (verifying data-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 simple optional bool field — 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

  1. (Minor, non-blocking) Consider adding a typing test in lib/tests/streamlit/typing/ for st.container() to verify the autoscroll parameter 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.

@lukasmasuch
Copy link
Copy Markdown
Collaborator Author

lukasmasuch commented Mar 24, 2026

QA Test Artifacts

@lukasmasuch lukasmasuch changed the title [feature] Add autoscroll parameter to st.container [feature] Add autoscroll parameter to st.container Mar 24, 2026
Copy link
Copy Markdown
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I like the test artifacts!

@lukasmasuch lukasmasuch merged commit 3b6023f into develop Mar 26, 2026
57 checks passed
@lukasmasuch lukasmasuch deleted the lukasmasuch/container-autoscroll branch March 26, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add “bottom” scroll behavior to container

3 participants