Skip to content

chore: add missing accent- warning in dev#479

Open
Brentlok wants to merge 1 commit intomainfrom
accent-warnings
Open

chore: add missing accent- warning in dev#479
Brentlok wants to merge 1 commit intomainfrom
accent-warnings

Conversation

@Brentlok
Copy link
Copy Markdown
Contributor

@Brentlok Brentlok commented Mar 27, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added development warnings to help identify missing color utility class configurations, enabling better debugging.
  • Refactor

    • Reorganized internal hook structure for improved code maintainability and clarity.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

The PR refactors accent color derivation across native and web components by introducing dedicated useAccentColor hooks, consolidating the isDefined utility to a common location, and adding development-time warnings when accent colors cannot be resolved from provided class names.

Changes

Cohort / File(s) Summary
Utility & Common Exports
packages/uniwind/src/common/utils.ts
Added isDefined generic type guard function to check for non-null/undefined values and narrow types to NonNullable<T>.
Native Component Accent Color Resolution
packages/uniwind/src/components/native/useAccentColor.ts
New hook that computes accent color via useStyle() with built-in development-only warning when class is provided but accentColor is undefined.
Native Components - Refactored to Use useAccentColor
packages/uniwind/src/components/native/ActivityIndicator.tsx, Button.tsx, FlatList.tsx, Image.tsx, ImageBackground.tsx, InputAccessoryView.tsx, Modal.tsx, RefreshControl.tsx, ScrollView.tsx, SectionList.tsx, Switch.tsx, Text.tsx, TextInput.tsx, TouchableHighlight.tsx, VirtualizedList.tsx
Replaced inline useStyle(...).accentColor calls with dedicated useAccentColor() hook for color properties (color, tintColor, endFillColor, backgroundColor, backdropColor, etc.). Component rendering logic and prop forwarding unchanged.
Web Component Import Reorganization
packages/uniwind/src/components/web/useUniwindAccent.ts
New local module exporting useUniwindAccent hook (formerly in hooks). Resolves class-derived styles and returns formatted accent color or undefined, with development-only warning support.
Web Components - Updated Hook Imports
packages/uniwind/src/components/web/ActivityIndicator.tsx, Button.tsx, Image.tsx, ImageBackground.tsx, Switch.tsx, TextInput.tsx, TouchableHighlight.tsx
Updated useUniwindAccent imports from ../../hooks to local ./useUniwindAccent module. No functional logic changes.
Hooks Module Cleanup
packages/uniwind/src/hooks/index.ts, packages/uniwind/src/hooks/useUniwindAccent.ts
Removed useUniwindAccent re-export from barrel file and deleted original hook implementation (now consolidated in component-specific modules).
Metro Utilities - isDefined Relocation
packages/uniwind/src/metro/addMetaToStylesTemplate.ts, packages/uniwind/src/metro/processor/css.ts, packages/uniwind/src/metro/processor/rn.ts, packages/uniwind/src/metro/utils/common.ts
Moved isDefined import/export from metro/utils/common.ts to common/utils.ts; updated three processor files to import from new location.
HOC Development Warnings
packages/uniwind/src/hoc/withUniwind.native.tsx, packages/uniwind/src/hoc/withUniwind.tsx
Added isDefined and Logger imports; introduced module-level warnedOnce flag and conditional warning emission when a color class is provided but accentColor resolution fails (guarded by __DEV__).
Test Setup
packages/uniwind/tests/setup.web.ts
Added globalThis.__DEV__ = true global before existing JSDOM mocks to enable development-only code paths in tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • jpudysz

Poem

🐰 A rabbit's ode to your refactor

With hooks now split and colors clear,
Each component finds its accent near,
No warnings buried, warnings bright,
When styles go missing in the night—
Utilities unified, the codebase cheers!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding development-mode warnings when accent color utilities are missing from class names across native and web components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch accent-warnings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 warnedOnce flag suppresses all warnings after the first one fires, regardless of which className triggered it. This reduces the warning's usefulness:

  1. TextInput calls this hook 5 times per render—if cursorColorClassName is invalid, warnings for other invalid classNames (selectionColorClassName, etc.) are silenced.
  2. If ComponentA triggers the warning, ComponentB with 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) and withUniwind.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

📥 Commits

Reviewing files that changed from the base of the PR and between 2fcfbe8 and ffbb45c.

📒 Files selected for processing (34)
  • packages/uniwind/src/common/utils.ts
  • packages/uniwind/src/components/native/ActivityIndicator.tsx
  • packages/uniwind/src/components/native/Button.tsx
  • packages/uniwind/src/components/native/FlatList.tsx
  • packages/uniwind/src/components/native/Image.tsx
  • packages/uniwind/src/components/native/ImageBackground.tsx
  • packages/uniwind/src/components/native/InputAccessoryView.tsx
  • packages/uniwind/src/components/native/Modal.tsx
  • packages/uniwind/src/components/native/RefreshControl.tsx
  • packages/uniwind/src/components/native/ScrollView.tsx
  • packages/uniwind/src/components/native/SectionList.tsx
  • packages/uniwind/src/components/native/Switch.tsx
  • packages/uniwind/src/components/native/Text.tsx
  • packages/uniwind/src/components/native/TextInput.tsx
  • packages/uniwind/src/components/native/TouchableHighlight.tsx
  • packages/uniwind/src/components/native/VirtualizedList.tsx
  • packages/uniwind/src/components/native/useAccentColor.ts
  • packages/uniwind/src/components/web/ActivityIndicator.tsx
  • packages/uniwind/src/components/web/Button.tsx
  • packages/uniwind/src/components/web/Image.tsx
  • packages/uniwind/src/components/web/ImageBackground.tsx
  • packages/uniwind/src/components/web/Switch.tsx
  • packages/uniwind/src/components/web/TextInput.tsx
  • packages/uniwind/src/components/web/TouchableHighlight.tsx
  • packages/uniwind/src/components/web/useUniwindAccent.ts
  • packages/uniwind/src/hoc/withUniwind.native.tsx
  • packages/uniwind/src/hoc/withUniwind.tsx
  • packages/uniwind/src/hooks/index.ts
  • packages/uniwind/src/hooks/useUniwindAccent.ts
  • packages/uniwind/src/metro/addMetaToStylesTemplate.ts
  • packages/uniwind/src/metro/processor/css.ts
  • packages/uniwind/src/metro/processor/rn.ts
  • packages/uniwind/src/metro/utils/common.ts
  • packages/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

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.

1 participant