fix: add missing size property to DynamicIcon class#5665
Conversation
Fixes reflex-dev#5660 where rx.icon size attribute was ignored when using dynamic state variables vs static strings. The DynamicIcon class was missing the size: Var[int] property definition, causing size to be treated as CSS style instead of a direct component prop. This resulted in dynamic icons falling back to Lucide React's default size of 24px instead of using the specified size. Changes: - Add size: Var[int] property to DynamicIcon class - Ensures consistent size handling between static and dynamic icons - Both now pass size as proper component props to Lucide React
There was a problem hiding this comment.
Greptile Summary
This PR fixes a critical bug in the Reflex icon system where dynamic icons (using state variables) were ignoring the size parameter. The issue occurred because the DynamicIcon class was missing the size: Var[int] property definition that exists in the base Icon class.
When using static icon names like rx.icon("home", size=16), the Icon.create() method returns an Icon instance with the proper size property. However, when using dynamic state variables like rx.icon(State.icon, size=16), the method returns a DynamicIcon instance (line 69 in the create method). Without the size property definition, the size parameter was being treated as a CSS style rather than a component prop, causing the underlying Lucide React component to ignore it and fall back to its default 24px size.
The fix adds the missing size: Var[int] property to the DynamicIcon class, ensuring both static and dynamic icons have identical property interfaces. This maintains consistent behavior regardless of whether the icon name is provided as a static string or dynamic state variable. The change integrates seamlessly with the existing component architecture, as both classes now share the same property definitions and follow the same rendering path through the Lucide React component system.
The PR also updates the corresponding .pyi hash file to reflect the type stub changes, which is standard practice for maintaining type safety in the codebase.
Confidence score: 5/5
- This PR is extremely safe to merge with minimal risk of introducing any issues
- Score reflects a simple, well-targeted bug fix that adds a missing property definition without changing any existing logic or behavior
- No files require special attention as this is a straightforward one-line addition with clear intent and purpose
2 files reviewed, no comments
CodSpeed Performance ReportMerging #5665 will not alter performanceComparing Summary
Footnotes |
|
thanks for the fix :) |
All Submissions:
Type of change
Changes To Core Features:
Description
Fixes #5660 where
rx.iconsize attribute was ignored when using dynamic state variables vs static strings.The DynamicIcon class was missing the size: Var[int] property definition, causing size to be treated as CSS style instead of a direct component prop. This resulted in dynamic icons falling back to Lucide React's default size of 24px instead of using the specified size.
Problem
rx.icon("home", size=16)worked correctly (16x16 pixels)rx.icon(State.icon, size=16)was broken (fell back to Lucide's default 24px)Root Cause
The
DynamicIconclass was missing thesize: Var[int]property definition, causing the size parameter to be treated as a CSS style instead of a direct componentprop.
Solution
Added the missing
size: Var[int]property to theDynamicIconclass, ensuring consistent size handling between static and dynamic icons.Testing
closes #5660