prevent tag special props from being a shared mutable reference#5640
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR fixes a critical shared mutable reference bug in the component rendering system. The issue occurs in the Component._render() method where special_props was being passed by reference to Tag objects, causing multiple component instances to inadvertently share the same list.
The fix changes special_props=self.special_props to special_props=self.special_props.copy() on line 967 of reflex/components/component.py. This ensures each Tag gets its own independent copy of the special props list, preventing cross-component contamination.
This change addresses a classic Python mutable default argument issue. The special_props field is defined as a list with a default factory, but when creating Tag objects, the same list reference was being shared across multiple instances. This likely manifested when rendering multiple components (like plotly graphs mentioned in the branch name) where modifications to one component's special_props would affect other components.
The fix integrates seamlessly with the existing component architecture without changing any APIs or breaking existing functionality. It's a defensive programming practice that prevents subtle bugs in component rendering.
Confidence score: 5/5
- This is an extremely safe fix that prevents a serious shared state bug with no downside
- The change is minimal, well-targeted, and follows Python best practices for avoiding mutable reference issues
- No files need additional attention - this is a straightforward defensive copy operation
1 file reviewed, no comments
CodSpeed Performance ReportMerging #5640 will not alter performanceComparing Summary
|
ideally this guy should be mutable