Conversation
📝 WalkthroughWalkthroughThe PR refactors accent color derivation across native and web components by introducing dedicated Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/uniwind/src/components/native/useAccentColor.ts (1)
6-16: Consider tracking warned classNames in a Set instead of a single boolean.The module-level
warnedOnceflag suppresses all warnings after the first one fires, regardless of which className triggered it. This reduces the warning's usefulness:
TextInputcalls this hook 5 times per render—ifcursorColorClassNameis invalid, warnings for other invalid classNames (selectionColorClassName, etc.) are silenced.- If
ComponentAtriggers the warning,ComponentBwith a completely different invalid className will never warn.A Set-based approach would warn once per unique className, providing better developer feedback:
♻️ Suggested improvement using a Set
-let warnedOnce = false +const warnedClassNames = new Set<string>() export const useAccentColor = (className: string | undefined, componentProps: Record<string, any>, state?: ComponentState) => { const styles = useStyle(className, componentProps, state) - if (__DEV__ && !warnedOnce && isDefined(className) && className.trim() !== '' && styles.accentColor === undefined) { - warnedOnce = true + if (__DEV__ && isDefined(className) && className.trim() !== '' && styles.accentColor === undefined && !warnedClassNames.has(className)) { + warnedClassNames.add(className) Logger.warn( `className '${className}' was provided to extract accentColor but no color was found. Make sure the className includes a color utility (e.g., 'accent-red-500', 'accent-blue-600').`, ) } return styles.accentColor }If you adopt this change, the same pattern should be applied to
withUniwind.native.tsx(line 11) andwithUniwind.tsx(line 10) for consistency.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/uniwind/src/components/native/useAccentColor.ts` around lines 6 - 16, Replace the module-level boolean warnedOnce in useAccentColor with a module-level Set to track which className strings have already triggered a warning: in useAccentColor, when __DEV__ and styles.accentColor is undefined and className is defined/trimmed, check the Set for that className and only call Logger.warn and add the className to the Set if it wasn’t present; update the reference to warnedOnce accordingly (remove the boolean) and mirror the same Set-based deduplication for the warning logic in withUniwind.native.tsx and withUniwind.tsx so each unique invalid className warns only once per process.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/uniwind/src/hoc/withUniwind.tsx`:
- Around line 36-41: The condition that calls className.trim() can throw when
props.className is not a string; update the guard in the conditional that
references warnedOnce, className and color (the block that logs via Logger.warn)
to first check typeof className === 'string' before calling className.trim();
i.e., ensure the if uses a runtime string check (typeof className === 'string')
combined with isDefined(className) and className.trim() !== '' so trim() is only
invoked on actual strings, leaving warnedOnce and Logger.warn logic unchanged.
In `@packages/uniwind/tests/setup.web.ts`:
- Around line 3-6: The global __DEV__ in tests causes module-level warning
guards (the warnedOnce flags used in
packages/uniwind/src/components/web/useUniwindAccent.ts and
packages/uniwind/src/hoc/withUniwind.tsx) to persist across test cases and make
warnings order-dependent; update tests/setup.web.ts to reset those module-level
flags between tests by either (a) calling a reset helper or directly clearing
the warnedOnce variables on the imported modules after each test (or before all
tests), or (b) ensure tests call jest.resetModules()/module isolation so the
modules (useUniwindAccent and withUniwind) are re-imported fresh; reference the
warnedOnce symbols and those module names so implementers know which flags to
clear or which modules to reload.
---
Nitpick comments:
In `@packages/uniwind/src/components/native/useAccentColor.ts`:
- Around line 6-16: Replace the module-level boolean warnedOnce in
useAccentColor with a module-level Set to track which className strings have
already triggered a warning: in useAccentColor, when __DEV__ and
styles.accentColor is undefined and className is defined/trimmed, check the Set
for that className and only call Logger.warn and add the className to the Set if
it wasn’t present; update the reference to warnedOnce accordingly (remove the
boolean) and mirror the same Set-based deduplication for the warning logic in
withUniwind.native.tsx and withUniwind.tsx so each unique invalid className
warns only once per process.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f60efbd9-08b9-4db3-86e7-82b89acf6d8c
📒 Files selected for processing (34)
packages/uniwind/src/common/utils.tspackages/uniwind/src/components/native/ActivityIndicator.tsxpackages/uniwind/src/components/native/Button.tsxpackages/uniwind/src/components/native/FlatList.tsxpackages/uniwind/src/components/native/Image.tsxpackages/uniwind/src/components/native/ImageBackground.tsxpackages/uniwind/src/components/native/InputAccessoryView.tsxpackages/uniwind/src/components/native/Modal.tsxpackages/uniwind/src/components/native/RefreshControl.tsxpackages/uniwind/src/components/native/ScrollView.tsxpackages/uniwind/src/components/native/SectionList.tsxpackages/uniwind/src/components/native/Switch.tsxpackages/uniwind/src/components/native/Text.tsxpackages/uniwind/src/components/native/TextInput.tsxpackages/uniwind/src/components/native/TouchableHighlight.tsxpackages/uniwind/src/components/native/VirtualizedList.tsxpackages/uniwind/src/components/native/useAccentColor.tspackages/uniwind/src/components/web/ActivityIndicator.tsxpackages/uniwind/src/components/web/Button.tsxpackages/uniwind/src/components/web/Image.tsxpackages/uniwind/src/components/web/ImageBackground.tsxpackages/uniwind/src/components/web/Switch.tsxpackages/uniwind/src/components/web/TextInput.tsxpackages/uniwind/src/components/web/TouchableHighlight.tsxpackages/uniwind/src/components/web/useUniwindAccent.tspackages/uniwind/src/hoc/withUniwind.native.tsxpackages/uniwind/src/hoc/withUniwind.tsxpackages/uniwind/src/hooks/index.tspackages/uniwind/src/hooks/useUniwindAccent.tspackages/uniwind/src/metro/addMetaToStylesTemplate.tspackages/uniwind/src/metro/processor/css.tspackages/uniwind/src/metro/processor/rn.tspackages/uniwind/src/metro/utils/common.tspackages/uniwind/tests/setup.web.ts
💤 Files with no reviewable changes (3)
- packages/uniwind/src/metro/utils/common.ts
- packages/uniwind/src/hooks/index.ts
- packages/uniwind/src/hooks/useUniwindAccent.ts
Summary by CodeRabbit
Release Notes
New Features
Refactor