feat(ui): make cva variants optional and add cx sugar#8823
feat(ui): make cva variants optional and add cx sugar#8823alexcarpenter wants to merge 2 commits into
Conversation
Variants on the Mosaic cva config are now optional, and a new cx helper covers the base-only case.
🦋 Changeset detectedLatest commit: 155ce16 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughcva now accepts configs without variants (typing and implementation), inlines variant resolution, ensures tooling metadata (_variants/_defaultVariants) defaults to empty objects when absent, introduces a new cx helper for base-only styles, adds tests for both cva without variants and cx, and adds a changeset. ChangesOptional Variants and cx Helper for cva Utility
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
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 |
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
API Changes Report
Summary
No API Changes DetectedAll packages have stable APIs with no detected changes. Report generated by Break Check Last ran on |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.changeset/cva-optional-variants.md:
- Around line 1-2: The changeset file is empty; replace the bare `---` contents
with a proper changeset entry that lists the affected package (e.g., `@clerk/ui:
minor`) and a short summary describing the change (make `variants` optional and
add the new `cx` export/helper), so the release tooling will create a minor bump
for the UI package and document the feature; ensure the summary mentions both
"optional variants" and "new cx helper/export" and save the file with the same
filename.
🪄 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: Repository YAML (base), Repository UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 231be202-0711-4699-940f-ea7913042388
📒 Files selected for processing (3)
.changeset/cva-optional-variants.mdpackages/ui/src/mosaic/__tests__/cva.test.tspackages/ui/src/mosaic/cva.ts
| --- | ||
| --- |
There was a problem hiding this comment.
Empty changeset for a feature PR.
This changeset file contains only the --- delimiters with no package entries or summary. Based on learnings, empty changesets are acceptable only for documentation-only or internal-tooling PRs that do not affect published packages.
This PR adds a new cx export and makes the variants field optional—a feature addition to packages/ui. A proper changeset should include:
- The package name (
@clerk/uior equivalent) with aminorbump (new feature) - A summary describing the optional variants and the new
cxhelper
📝 Example changeset content
---
+'`@clerk/ui`': minor
---
+
+Make the `variants` field optional in `cva` config and add a new `cx` helper for base-only styles without variants. The `cx` function is a thin wrapper around `cva({ base })` that returns a full `CvaFn` compatible with tooling.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.changeset/cva-optional-variants.md around lines 1 - 2, The changeset file
is empty; replace the bare `---` contents with a proper changeset entry that
lists the affected package (e.g., `@clerk/ui: minor`) and a short summary
describing the change (make `variants` optional and add the new `cx`
export/helper), so the release tooling will create a minor bump for the UI
package and document the feature; ensure the summary mentions both "optional
variants" and "new cx helper/export" and save the file with the same filename.
Source: Learnings
Fold variant resolution into the merge loop, building the compound-match map lazily so components without compound variants skip the allocation and an extra pass.
Makes
variantsoptional on the Mosaiccvaconfig, adds acxhelper for the no-variants case, and resolves variants in a single pass.cvawithout variantscxsugarcxis a thin wrapper overcva({ base })returning a fullCvaFnwith empty_variants/_defaultVariants, so swingsetmeta.styles, PropTable, and knob generation keep working (PropTable just showssx).Single-pass variant resolution
Variant resolution previously allocated an intermediate map and made a second pass over the variant keys. That map is only needed to match compound variants, so it's now built lazily and folded into the merge loop — components without compound variants (the common case) skip the allocation and the extra pass. The
resolveVariantshelper is removed.Measured ~4–5% on the resolver path (the deep merge dominates, so this isn't a critical fix — cva was never a bottleneck — but it removes an allocation, a pass, and a helper).
Notes
_variants/_defaultVariantsdefensively (?? {}), so empty/absent variants are safe.tsc --noEmitclean.