Merged
Conversation
Contributor
There was a problem hiding this comment.
Greptile Overview
Summary
This PR reverts color handling changes that were introduced in v0.8.13, which caused critical runtime errors in JavaScript components, particularly affecting chart components like FunnelChart. The main issue was that the previous implementation was serializing Color objects as complex JavaScript objects using `Object.assign(new String(...))` instead of primitive strings, causing "String.prototype.valueOf requires that 'this' be a String" errors.The revert affects multiple parts of the color system:
- Color Serialization: The
serialize_colorfunction inutils/serializers.pynow returnscolor.__format__("")directly instead of complex object structures - Style Processing: Removes special Color handling in
style.pythat was converting Color objects toLiteralColorVarinstances - Color Class: The
Color.__format__method inconstants/colors.pyreverts from usingLiteralColorVarback to callingformat_color()directly - Color Variables: The
ColorVarclass invars/color.pyis simplified to generate plain CSS variable strings like"var(--mint-7)"instead of complex JavaScript expressions - Test Updates: All corresponding tests are updated to expect simple string outputs rather than complex object expressions
The core problem was that many JavaScript libraries and Reflex components expect primitive string values for CSS colors, but the v0.8.13 implementation was providing non-primitive String object wrappers. This broke compatibility with third-party charting libraries and other components that perform string operations on color values. The revert ensures that Color objects are serialized as simple CSS variable strings throughout the system, maintaining backward compatibility while fixing the runtime errors.
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| reflex/utils/serializers.py | 4/5 | Reverts Color serialization to return simple CSS variable strings instead of complex objects |
| reflex/style.py | 4/5 | Removes special Color object processing that was causing JavaScript compatibility issues |
| tests/units/utils/test_serializers.py | 5/5 | Updates test expectations to match reverted simple string Color serialization |
| tests/units/components/core/test_colors.py | 5/5 | Updates color variable tests to expect simple string outputs instead of complex JavaScript expressions |
| reflex/constants/colors.py | 4/5 | Reverts Color.format method from LiteralColorVar back to direct format_color() calls |
| reflex/vars/color.py | 4/5 | Simplifies ColorVar class to generate plain CSS strings instead of complex JavaScript objects |
| tests/units/components/test_component.py | 5/5 | Updates component test to expect simple color string instead of Object.assign expression |
Confidence score: 4/5
- This PR is safe to merge as it fixes critical runtime errors affecting chart components
- Score reflects that this is a revert addressing a well-documented breaking change with clear test coverage
- Pay close attention to reflex/utils/serializers.py and reflex/vars/color.py as they contain the core serialization logic
Sequence Diagram
sequenceDiagram
participant User
participant ColorAPI as "rx.color()"
participant StyleProcessor as "Style Processor"
participant Serializer as "Color Serializer"
participant Frontend as "Frontend CSS"
User->>ColorAPI: "Create color with rx.color('mint', 7)"
ColorAPI->>StyleProcessor: "Color(color='mint', shade=7, alpha=False)"
StyleProcessor->>StyleProcessor: "Format color for CSS"
StyleProcessor->>Serializer: "Serialize Color object"
Serializer->>Serializer: "color.__format__('')"
Serializer->>Frontend: "var(--mint-7)"
Frontend->>User: "Rendered component with CSS color"
7 files reviewed, no comments
CodSpeed Performance ReportMerging #5844 will not alter performanceComparing Summary
|
masenf
approved these changes
Oct 2, 2025
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.
it seems there are just too many things not handling nonprimitive strings: #5840