07-Migration Guide: Hikari to Tairitsu
Overview
This guide documents the migration of Hikari's core infrastructure to the Tairitsu build chain. It covers the completed phases and provides technical details for each migration.
Table of Contents
- Phase 2: CSS Infrastructure Migration
- Phase 3: Props Macro Migration
- Architecture Decisions
- Migration Results
Phase 2: CSS Infrastructure Migration
Status: Completed
Objectives
Migrate CSS infrastructure from internal implementation to tairitsu-style, a shared utility library.
Completed Work
1. StyleStringBuilder and CssProperty Migration
Before:
// packages/animation/src/properties.rs
After:
// packages/animation/src/style/mod.rs
// Re-export from tairitsu_style
pub use ;
// Now provides 403 W3C standard properties
Migration Steps:
- 1Added tairitsu-style dependency to hikari-animation:
# packages/animation/Cargo.toml
[dependencies]
tairitsu-style = { path = "../../../tairitsu/packages/style" }
- 1Updated hikari-animation/src/style/mod.rs:
pub use ;
// Keep StyleBuilder (HtmlElement version) for web-sys integration
- 1Deleted packages/animation/src/properties.rs (635 lines removed)
- 1Updated all imports across the codebase:
// Before
use CssProperty;
// After (automatic due to re-export)
use CssProperty;
Benefits
- 403 CSS Properties: From ~50 manually defined properties to 403 W3C standard properties
- Code Reduction: Removed 635 lines of duplicate code
- Consistency: Standardized property names with W3C specifications
- Maintainability: Property definitions centralized in tairitsu-style
Phase 3: Props Macro Migration
Status: Completed
Objectives
Migrate all component Props from the old #[derive(Clone, PartialEq, Props)] to the new #[define_props] macro.
Migration Pattern
Before:
After:
// Default implementation auto-generated by #[define_props]
Key Changes
- 1Macro Change: #[derive(Clone, PartialEq, Props)] → #[define_props]
- 2Attribute Change: #[props(default)] → #[default(...)]
- 3Remove Manual Default: Delete impl Default for ... blocks
- 4Explicit Values: Provide concrete default values for all fields
Migration Rules
| Type | Default Value | Example | ||
|---|---|---|---|---|
| String | String::default() or "".to_string() | #[default(String::default())] | ||
| bool | false or true | #[default(false)] | ||
| u32/i32/i64 | 0 or other number | #[default(0)] or #[default(10)] | ||
| Vec<T> | Vec::new() or vec![] | #[default(Vec::new())] | ||
| Element | VNode::empty() | #[default(VNode::empty())] | ||
| Option<T> | No default needed (impls Default) | - | ||
| Enum (with Default) | No default needed | - | ||
| EventHandler | `EventHandler::new(\ | _ {} )` | `#[default(EventHandler::new(\ | _ {}))]` |
Completed Migrations
Basic Components
- ButtonProps yes
- InputProps yes
- TextareaProps yes
- BadgeProps yes
- CardProps, CardHeaderProps, CardContentProps, CardActionsProps, CardMediaProps yes
- SliderProps yes
- SwitchProps yes
- CheckboxProps yes
- RadioProps, RadioGroupProps yes
- IconButtonProps yes
Layout Components
- FlexBoxProps yes
Feedback Components
- AlertProps yes
- ToastProps yes
- TooltipProps yes
- DrawerProps yes
- ProgressProps yes
- SpinProps yes
- PopoverProps yes
- GlowProps yes
Navigation Components
- StepperProps yes
- BreadcrumbProps, BreadcrumbItemProps yes
- TabProps, TabPanelProps yes
- MenuItemProps, etc. yes
- SidebarProps, SidebarSectionProps, SidebarItemProps, SidebarLeafProps yes
Display Components
- TagProps yes
- CalendarProps yes
- TimelineProps, TimelineItemProps yes
- QRCodeProps yes
Entry Components
- NumberInputProps yes
- SearchProps yes
- AutoCompleteProps yes
- CascaderProps yes
- TransferProps, TransferItem yes
Data Components
- TableProps yes
- PaginationProps yes
- VirtualScrollProps yes
- DragProps, DragTreeNodeData yes
Production Components
- CodeHighlightProps yes
- MarkdownEditorProps yes
- RichTextEditorProps yes
- VideoPlayerProps yes
- AudioPlayerProps yes
Icon Components
- IconProps yes
Benefits
- Reduced Boilerplate: Auto-generated Default implementations
- Type Safety: Compile-time checking of default values
- Consistency: Uniform API across all components
- Maintainability: Single source of truth for Props definition
Architecture Decisions
ClassesBuilder and UtilityClass Retention
Decision: ClassesBuilder and UtilityClass trait remain in hikari-palette.
Reasons:
- 1Different Purposes:
- tairitsu-style: Tailwind-style utility classes for CSS generation
- hikari-palette: Hikari component-specific hi- prefix class enums
- 1API Incompatibility:
- Tailwind utility classes use hyphenated naming (e.g., flex, items-center)
- Hikari classes use enum-based naming (e.g., Display::Flex, FlexDirection::Col)
- 1Component Coupling:
- Hikari has 18 component class enum files
- These enums are tightly coupled with the hi- prefix style system
Architecture:
Migration Results
Code Metrics
| Metric | Before | After | Change |
|---|---|---|---|
| CSS Properties | ~50 | 403 | +706% |
| Properties Code Lines | 635 | 0 | -100% |
| Components Migrated | 0 | 47 | - |
| Manual Default Impls | 47 | 0 | -100% |
Compilation Status
- All packages compile successfully
- No compilation errors
- All tests passing (78/78 in hikari-components)
- Minor warnings (dead code in unrelated files)
Test Updates
Pagination Test Fix:
Modified tests to use individual field assertions instead of whole-struct assertions:
// Before
assert_eq!;
// After
assert!;
assert!;
// ... etc
This avoids requiring the Debug trait on Props generated by #[define_props].
Future Work
Phase 4: Documentation Updates
- [x] Update docs/en-US/guides/02-classesbuilder-system.md
- [x] Update docs/en-US/guides/03-stylestringbuilder-system.md
- [x] Add migration guide (this document)
Translation
All documentation updates should be translated to all supported languages:
- zh-CHS (Simplified Chinese)
- zh-CHT (Traditional Chinese)
- ja-JP (Japanese)
- ko-KR (Korean)
- es-ES (Spanish)
- fr-FR (French)
- ru-RU (Russian)
- ar-SA (Arabic)
Conclusion
The migration to Tairitsu build chain has been successfully completed for:
- 1Phase 2: CSS Infrastructure - 403 W3C CSS properties integrated
- 2Phase 3: Props Macro - All 47 components migrated to #[define_props]
All code compiles, tests pass, and the codebase is ready for the next phase of development.