Conversation
✅ 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!
|
4bc1388 to
a27a540
Compare
6ec879b to
6f2a490
Compare
5d5f3a8 to
f90346e
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new st.space API that allows developers to add customizable spacing between elements in both vertical and horizontal layouts. The space element supports predefined sizes ("small", "medium", "large"), a "stretch" option to fill remaining space, and custom pixel values.
Key changes:
- Added new space element with flexible sizing options including preset values and pixel dimensions
- Implemented comprehensive test coverage for both unit and end-to-end scenarios
- Integrated the space functionality into Streamlit's element system and public API
Reviewed Changes
Copilot reviewed 8 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/streamlit/elements/space.py | Core implementation of the space element with size validation and layout configuration |
| lib/streamlit/delta_generator.py | Integration of SpaceMixin into the DeltaGenerator class hierarchy |
| lib/streamlit/init.py | Export of space function in the public API |
| lib/tests/streamlit/elements/space_test.py | Unit tests covering all space size options and error cases |
| lib/tests/streamlit/element_mocks.py | Added space element to test mocks |
| lib/streamlit/testing/v1/element_tree.py | Testing framework support for space elements |
| e2e_playwright/st_space_test.py | End-to-end tests for space rendering and behavior |
| e2e_playwright/st_space.py | Test application demonstrating space usage in various contexts |
lib/streamlit/elements/space.py
Outdated
| return self.dg._enqueue( # type: ignore[attr-defined,no-any-return] | ||
| "space", space_proto, layout_config=layout_config | ||
| ) |
There was a problem hiding this comment.
Why is the # type: ignore[attr-defined,no-any-return] needed here but not for any other command?
There was a problem hiding this comment.
Hmmm I think this is probably a mistake from the agent. At one point it did the wrong thing with fixing the types for layout_config and maybe this is residual. I will take a look.
There was a problem hiding this comment.
question: There still seems to be some space after the After stretch space. I would have expected that the stretch fills all available space. Why is that the case?
There was a problem hiding this comment.
Yes, this is because I used st.write() statements and they are stretch width so the extra space is distributed amongst the elements (including st.space). It also looks a bit unexpected because the text is left-aligned so the last st.write() statement appears different than the first one.
I decided to update to st.markdown(width="content") for the test -- that shows the space a better.
e2e_playwright/st_space_test.py
Outdated
| first_space_box = first_space.bounding_box() | ||
| assert first_space_box is not None | ||
| assert int(first_space_box["height"]) == 40 # 2.5rem * 16px = 40px | ||
|
|
||
| # Second space: st.space("large") = 4.25rem = 68px height | ||
| second_space = space_elements.nth(1) | ||
| second_space_box = second_space.bounding_box() | ||
| assert second_space_box is not None | ||
| assert int(second_space_box["height"]) == 68 # 4.25rem * 16px = 68px |
There was a problem hiding this comment.
not sure if it is the case here, but it might be better to use a wait_until to prevent flakiness, e.g.:
streamlit/e2e_playwright/st_set_page_config_test.py
Lines 49 to 53 in b15e4cc
6f2a490 to
63b78b9
Compare
f90346e to
153ea80
Compare
📉 Frontend coverage change detectedThe frontend unit test (vitest) coverage has decreased by 0.0000%
✅ Coverage change is within normal range. |
153ea80 to
8117630
Compare
63b78b9 to
d22d189
Compare
8117630 to
e1d755a
Compare
5b76187 to
cf3ad90
Compare
e1d755a to
9a4e9f8
Compare
9a4e9f8 to
2be7fb5
Compare
cf3ad90 to
fcda0e6
Compare
fcda0e6 to
e01c6b3
Compare
2be7fb5 to
74caadd
Compare
74caadd to
6be291f
Compare
991a1ca to
918e5c2
Compare
…rclass `__init__` during object initialization Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
918e5c2 to
5f5d473
Compare
| assert_snapshot(nested_container, name="st_space_nested_containers") | ||
|
|
||
|
|
||
| def test_space_sizes_match_widget_heights(app: Page): |
There was a problem hiding this comment.
This test addresses some feedback from Lukas from the previous PR about making sure we keep the values in sync between backend and frontend #12736 (comment)

Describe your changes
Adds a new element,
st.space. Use this to add space in between elements in vertical and horizontal layouts!E.g.
st.space("stretch"),st.space("medium"),st.space(100).GitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.