Skip to content

Conversation

@sfc-gh-bnisco
Copy link
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco commented Dec 6, 2025

Describe your changes

Improved CSS custom property serialization in the BidiComponent theme utility:

  • Added special handling for widgetBorderColor to use 'transparent' instead of 'unset' when the value is null or undefined
  • Enhanced serialization logic to handle different value types more robustly:
    • Arrays are joined with commas
    • Null/undefined values use the CSS-wide 'unset' keyword
    • Added defensive fallback for unexpected value types
  • Added comprehensive tests to verify the new serialization behavior

Testing Plan

  • Unit Tests: Added test cases to verify the special handling of widgetBorderColor and the general serialization of null/undefined values for both widget and non-widget properties.

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
Contributor

snyk-io bot commented Dec 6, 2025

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

Status Scanner 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
Contributor

github-actions bot commented Dec 6, 2025

✅ PR preview is ready!

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

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sfc-gh-bnisco sfc-gh-bnisco added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Dec 6, 2025
@sfc-gh-bnisco sfc-gh-bnisco requested a review from Copilot December 6, 2025 00:35
Copy link
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

This PR improves CSS custom property serialization in the BidiComponent theme utility to handle edge cases more robustly.

  • Added special handling for widgetBorderColor to use 'transparent' instead of 'unset' when null/undefined
  • Enhanced the serialization logic to properly handle null/undefined values, arrays, and unexpected types
  • Added comprehensive unit tests to verify the new behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
frontend/lib/src/components/widgets/BidiComponent/utils/theme.ts Enhanced objectToCssCustomProperties function with special case handling for widgetBorderColor, general null/undefined handling using 'unset', array serialization, and defensive fallback for unexpected types
frontend/lib/src/components/widgets/BidiComponent/utils/theme.test.ts Added parameterized tests to verify special handling of null/undefined widgetBorderColor and general null/undefined property serialization

Copy link
Collaborator

Choose a reason for hiding this comment

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

Question: In protoFieldsToIgnore (line 249), widgetBorderColor is listed - should we be passing this in CCv2 since it is a deprecated property?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good point!

The scenario we want to support is "if showWidgetBorders is false, then set this variable to transparent, else set this variable to the border color." Given what you said, would it make sense to expose this under a different name?

Copy link
Collaborator

Choose a reason for hiding this comment

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

My preference would be to expose this under a different name like widgetBorderStyle to distinguish, and because its more accurate to the property as a computed style value (not just a color).

Unfortunately we previously mixed concerns with the same name for a deprecated config (themeInput) property, widgetBorderColor that is just the color, and the computed theme output property theme.colors.widgetBorderColor which is a mix of a color and a boolean we use to determine whether widgets borders should be shown 😓 Once we update properties used by dependency teams off this deprecated one, can clean this up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you. I took another look at this and given the constraints here, I think what makes the most sense is to add widgetBorderStyle as a fully computed shorthand (eg: it evaluates to 1px solid yellow). This will be generated using the theme values.

Why I think this makes more sense is that widgetBorderStyle as a name could give the impression that it's a fully declared shorthand, not just a standalone color. The other benefit is that it makes actually using this much simpler, now users just need to write border: var(--st-widget-border-style), and their borders will immediately match the rest of the app's theme.

I just pushed an update that implements this, WDYT about this approach?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed that widgetBorderStyle would probably indicate full specification, though I don't love how that would decrease flexibility for border styling 🤔
I played around with a couple options and I think we are better off just keeping widgetBorderColor (not deprecating this output). This would entail having it use "transparent" instead of undefined, removing from protoFieldsToIgnore, with documentation that this is the computed output NOT the deprecated config.

Apologies for the back and forth, trying to balance all considerations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I appreciate the thoroughness! Pushing an update that just keeps widgetBorderColor with the fallback to transparent.

@sfc-gh-bnisco sfc-gh-bnisco force-pushed the 12-05-_fix_handle_undefined_theme_properties_in_ccv2 branch 3 times, most recently from 2cc6f60 to e7d4452 Compare December 13, 2025 00:22
@github-actions
Copy link
Contributor

github-actions bot commented Dec 13, 2025

📈 Frontend coverage change detected

The frontend unit test (vitest) coverage has increased by 0.0100%

  • Current PR: 86.3400% (12607 lines, 1722 missed)
  • Latest develop: 86.3300% (12598 lines, 1721 missed)

✅ Coverage change is within normal range.

📊 View detailed coverage comparison

@sfc-gh-bnisco sfc-gh-bnisco force-pushed the 12-05-_fix_handle_undefined_theme_properties_in_ccv2 branch from e7d4452 to 4f3b27e Compare December 15, 2025 16:45
@sfc-gh-bnisco sfc-gh-bnisco marked this pull request as ready for review December 15, 2025 16:46
@sfc-gh-bnisco sfc-gh-bnisco enabled auto-merge (squash) December 15, 2025 16:46
@sfc-gh-bnisco sfc-gh-bnisco merged commit d6cbc4c into develop Dec 15, 2025
43 checks passed
@sfc-gh-bnisco sfc-gh-bnisco deleted the 12-05-_fix_handle_undefined_theme_properties_in_ccv2 branch December 15, 2025 17:22
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 security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants