Skip to content

[fix] Setting 0 for height/width on components.html and components.iframe . #12479

Merged
sfc-gh-lwilby merged 6 commits intodevelopfrom
fix/zero-dimension-html-iframe-components
Sep 12, 2025
Merged

[fix] Setting 0 for height/width on components.html and components.iframe . #12479
sfc-gh-lwilby merged 6 commits intodevelopfrom
fix/zero-dimension-html-iframe-components

Conversation

@sfc-gh-lwilby
Copy link
Copy Markdown
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby commented Sep 9, 2025

Describe your changes

GitHub Issue Link (if applicable)

Fixes #12454

Testing Plan

  • Unit Tests (JS and/or Python) ✅
  • E2E Tests ✅
  • Manually inspected ✅
  • Other elements have tests verifying that we validate no 0 width is allowed at the python layer so although this requires changes to common functions, we expect the change to be isolated.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Sep 9, 2025

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

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 9, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12479/streamlit-1.49.1-py3-none-any.whl
🕹️ Preview app pr-12479.streamlit.app (☁️ Deploy here if not accessible)

@sfc-gh-lwilby sfc-gh-lwilby added type:bug Something isn't working as expected security-assessment-completed impact:users PR changes affect end users change:bugfix PR contains bug fix implementation and removed type:bug Something isn't working as expected labels Sep 9, 2025
[
{ width: 0, height: 100 },
getDefaultStyles({
width: "auto",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is the default, so no change.

minStretchBehavior?: MinFlexElementWidth
}

const isPositiveNumber = (value: unknown): value is number =>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is used for validating pixelHeight and pixelWidth which are on the proto and validated before being set, so we shouldn't expect 0 measurements from something like a resizeObserver. We should only expect it when the python function allows it and sets the proto that way.

@sfc-gh-lwilby sfc-gh-lwilby marked this pull request as ready for review September 11, 2025 15:14
Comment on lines +171 to +174
expect(zero_html_container).to_have_attribute("width", "0px")
expect(zero_html_container).to_have_attribute("height", "0px")
expect(zero_html_container).to_have_css("width", "0px")
expect(zero_html_container).to_have_css("height", "0px")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: Consider removing the to_have_attribute calls since that asserts implementation details, whereas the to_have_css asserts what is actually rendered in the browsers. The to_have_css assertion should be both more powerful and less brittle, since the underlying implementation details may change over time.

Copy link
Copy Markdown
Contributor

@sfc-gh-nbellante sfc-gh-nbellante Sep 11, 2025

Choose a reason for hiding this comment

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

For my own understanding, if there's multiple classes with width and one of them has 0, would the to_have_css check come out to be true? And then if there's a width: 12 !important such that the resulting width is 12, would to_have_attribute("width", "0px") fail?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if there's multiple classes with width and one of them has 0, would the to_have_css check come out to be true?

It depends on which class wins based on CSS Precedence.

The big thing to note here is that to_have_attribute is asserting against what is literally in the DOM element, basically whatever is here: <div width="0">.

Note that CSS classes do not write this attribute to the DOM, therefore to_have_attribute is a brittle check. The other nuance here is that it looks like Emotion does write the width attribute, but that is an implementation detail, and one that we shouldn't rely on.

And then if there's a width: 12 !important such that the resulting width is 12, would to_have_attribute("width", "0px") fail?

Similar to above, to_have_attribute will fail. to_have_css("width", 0) would also fail.

I hope all of this info illustrates why to_have_css is a better assertion overall.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yup, that helps clarify a bunch. Thanks for the great explanation. :D

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, good point. The to_have_attribute assertion was added by the agent during an iteration to fix a failure, it was the wrong approach and the root cause was addressed, but I decided to leave both test assertions. I can't remember now why I thought I should leave both, but your argument makes a lot of sense.

@sfc-gh-lwilby sfc-gh-lwilby merged commit 4cc8cbc into develop Sep 12, 2025
38 checks passed
@sfc-gh-lwilby sfc-gh-lwilby deleted the fix/zero-dimension-html-iframe-components branch September 12, 2025 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

components.html(..., height=0) still renders ~150px vertical space (cannot collapse to 0)

3 participants