call to_string on colors coming into style#5836
Merged
adhami3310 merged 2 commits intomainfrom Sep 30, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Greptile Overview
Summary
This PR fixes issue #5835 by adding proper handling for rx.Color objects in the style system. The fix prevents rx.Color objects from being passed directly to emotion CSS-in-JS, which was causing compatibility issues.
- Added import for
Colorfromreflex.constants.colorsandLiteralColorVarfromreflex.vars.color - Implemented special case handling in
convert_item()function to detectColorinstances and convert them to proper CSS color strings usingLiteralColorVar.create(style_item).to_string(use_json=False) - The fix ensures
rx.Colorobjects are properly serialized to CSS color values likevar(--red-7)before being processed by emotion
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The fix is targeted and minimal, addressing a specific compatibility issue between rx.Color objects and emotion CSS-in-JS. The change follows established patterns in the codebase and uses existing infrastructure (LiteralColorVar) appropriately. The fix is well-contained within the convert_item function and doesn't affect other functionality.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| reflex/style.py | 5/5 | Added Color import and special handling in convert_item to convert Color objects to string format using LiteralColorVar |
Sequence Diagram
sequenceDiagram
participant User
participant Component
participant Style
participant ConvertItem
participant Color
participant LiteralColorVar
participant CSS
User->>Component: rx.button("Click me", bg_color=rx.color("red"))
Component->>Style: Style processing with Color object
Style->>ConvertItem: convert_item(Color("red"))
ConvertItem->>Color: isinstance(style_item, Color) check
Color-->>ConvertItem: True
ConvertItem->>LiteralColorVar: LiteralColorVar.create(color)
LiteralColorVar->>LiteralColorVar: to_string(use_json=False)
LiteralColorVar-->>ConvertItem: "var(--red-7)" string
ConvertItem-->>Style: (string_value, None)
Style-->>Component: Processed style
Component->>CSS: Render with CSS color value
1 file reviewed, no comments
CodSpeed Performance ReportMerging #5836 will not alter performanceComparing Summary
|
masenf
approved these changes
Sep 30, 2025
tartansandal
pushed a commit
to tartansandal/reflex
that referenced
this pull request
Oct 2, 2025
* call to_string on colors coming into style * fix unit tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #5835