Skip to content

Conversation

@timon0305
Copy link

Fixes #9362

Problem

Some components (Calendar, Drawer, Input OTP, Sonner) that use non-Radix libraries have cn-* classes that weren't being transformed during component generation. This happened because these components use cn-* classes in object properties (e.g., toastOptions={{ classNames: { toast: "cn-toast" } }}) rather than in standard className attributes.

Solution

Added a catch-all transformer applyToAllStringLiterals() that runs after the existing transformers to handle any remaining cn-* classes in:

  • Object property values
  • Nested object structures
  • Any other string literal context

The function includes isInAlreadyProcessedContext() to skip strings already handled by existing transformers (className attributes, cn() calls, cva() calls).

Changes

  • packages/shadcn/src/styles/transform-style-map.ts: Added applyToAllStringLiterals() and isInAlreadyProcessedContext() functions
  • packages/shadcn/src/styles/transform-style-map.test.ts: Added 4 test cases for object property transformation

Testing

All 946 existing tests pass, plus 4 new tests covering:

  • Sonner's toastOptions.classNames.toast pattern
  • Deeply nested object properties
  • Removal of unknown cn-* classes
  • Multiple cn-* classes in single property values

Add support for transforming cn-* classes that appear in object
property values (e.g., toastOptions={{ classNames: { toast: "cn-toast" } }}).

Previously, only cn-* classes in className attributes, cn() calls,
cva() calls, and mergeProps() were transformed. This left components
like Sonner, Calendar, Drawer, and Input OTP with untransformed
cn-* classes when they used non-standard patterns.

Changes:
- Add isInAlreadyProcessedContext() to detect already-handled contexts
- Add applyToAllStringLiterals() as catch-all for remaining cn-* classes
- Add tests for object property transformation patterns
@vercel
Copy link
Contributor

vercel bot commented Jan 19, 2026

@timon0305 is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

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.

[bug]: Styles add inconsistently for some components

1 participant