Skip to content

make tag immutable#5641

Merged
adhami3310 merged 5 commits into
mainfrom
make-tag-immutable
Jul 31, 2025
Merged

make tag immutable#5641
adhami3310 merged 5 commits into
mainfrom
make-tag-immutable

Conversation

@adhami3310
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
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 Summary

This PR implements a significant architectural change by making the Tag class and all its subclasses immutable throughout the Reflex codebase. The core change converts the Tag dataclass from mutable to immutable by adding frozen=True to the dataclass decorator and refactoring all mutation operations to return new instances instead of modifying existing ones.

Key changes include:

  1. Tag class immutability: The base Tag class is now frozen, with field types changed from concrete collections (dict, list) to abstract interfaces (Mapping, Sequence). The __post_init__ method that modified props in-place was removed.

  2. Method refactoring: All Tag methods (set(), add_props(), remove_props()) now use dataclasses.replace() to return new instances rather than mutating existing ones.

  3. Subclass consistency: All Tag subclasses (CondTag, MatchTag, IterTag) are now also frozen to maintain consistency in the inheritance hierarchy.

  4. Component rendering updates: Throughout the component system, code that previously mutated tags in-place has been updated to use method chaining and proper assignment patterns that work with immutable objects.

  5. Test updates: Test expectations have been updated to match the new Tag.iter behavior where props are returned as formatted strings rather than raw objects.

This change aligns with functional programming principles commonly used in React-like systems, where components should be treated as immutable data structures. The immutable design prevents accidental mutations that could lead to shared state bugs and improves thread safety during component rendering.

Confidence score: 4/5

• This is a well-structured refactoring that improves code safety and follows React best practices, but involves significant architectural changes across many files.
• The score reflects the comprehensive nature of the changes and potential for edge cases, though the implementation appears sound and all methods properly handle immutability.
• Files requiring extra attention: reflex/components/tags/tag.py (core Tag class changes), reflex/components/component.py (central rendering logic), and tests/units/components/test_tag.py (test assertion logic changes).

12 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jul 30, 2025

CodSpeed Performance Report

Merging #5641 will not alter performance

Comparing make-tag-immutable (4050feb) with main (f8e7b86)

Summary

✅ 8 untouched benchmarks

@adhami3310 adhami3310 merged commit 5161944 into main Jul 31, 2025
41 checks passed
@adhami3310 adhami3310 deleted the make-tag-immutable branch July 31, 2025 18:44
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