Skip to content

revert color handling#5844

Merged
adhami3310 merged 1 commit intomainfrom
revert-color-handling
Oct 2, 2025
Merged

revert color handling#5844
adhami3310 merged 1 commit intomainfrom
revert-color-handling

Conversation

@adhami3310
Copy link
Member

it seems there are just too many things not handling nonprimitive strings: #5840

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

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:

  1. Color Serialization: The serialize_color function in utils/serializers.py now returns color.__format__("") directly instead of complex object structures
  2. Style Processing: Removes special Color handling in style.py that was converting Color objects to LiteralColorVar instances
  3. Color Class: The Color.__format__ method in constants/colors.py reverts from using LiteralColorVar back to calling format_color() directly
  4. Color Variables: The ColorVar class in vars/color.py is simplified to generate plain CSS variable strings like "var(--mint-7)" instead of complex JavaScript expressions
  5. 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"
Loading

7 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 2, 2025

CodSpeed Performance Report

Merging #5844 will not alter performance

Comparing revert-color-handling (dc25caf) with main (42e77b1)

Summary

✅ 8 untouched

@adhami3310 adhami3310 merged commit 1fe61cf into main Oct 2, 2025
49 of 53 checks passed
@adhami3310 adhami3310 deleted the revert-color-handling branch October 2, 2025 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants