feat(core): emit recipe compoundVariants in the recipes layer#3519
feat(core): emit recipe compoundVariants in the recipes layer#3519lesderid wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 0d1f39f The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
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.
|
|
@lesderid is attempting to deploy a commit to the Chakra UI Team on Vercel. A member of the Team first needs to authorize it. |
|
Potential issue: this works because of the order in which these classes are emitted, but variant classes and compound variant classes are both in
@layer recipes {
@layer _base, _variants, _compound;
@layer _base { ... }
@layer _variants { ... }
@layer _compound { ... }
}
The second option seems like the cleanest solution to me, but the diff will probably be the largest (primarily because of test output changes). |
Move config recipe compoundVariants styles into the @layer recipes cascade layer so they can be overridden by atomic styles in @layer utilities via cx(). Each compound variant is assigned a deterministic class name of the form {recipe}--compound{separator}{index} (or {recipe}__{slot}--compound{separator}{index} for slot recipes) during recipe normalization, and the generated runtime joins those class names instead of re-extracting the compound CSS atomically. cva (atomic recipes) is intentionally unchanged.
c7b920e to
0d1f39f
Compare
🤖 Disclaimer
Built with GPT-5.4 and Opus 4.7, with human review and review by Opus 4.7.
📝 Description
Move config recipe
compoundVariantsstyles into the@layer recipescascadelayer so they can be overridden by atomic styles in
@layer utilitiesviacx(). Each compound variant is assigned a deterministic class name duringrecipe normalization, and the generated
createReciperuntime joins thoseclass names instead of re-extracting the compound CSS atomically.
Related: discussion #3493 (the layer-placement aspect; user-supplied
classNameon compound variants is intentionally not included here, see"Additional Information").
⛳️ Current behavior (updates)
compoundVariantsstyles on config recipes (and slot recipes) are emitted asatomic utilities in
@layer utilities. As a result, this does not work asexpected:
The compound variant's
backgroundand the atomicbackgroundend up in thesame layer, so the cascade falls back to declaration order in the stylesheet
rather than the user's
cx()order. Base and variant styles already live in@layer recipesand override correctly viacx(), compound variants werethe odd one out.
🚀 New behavior
Recipes.normalize, each compound variant entry gets a deterministicclass name
{recipe}--compound{separator}{index}(or{recipe}__{slot}--compound{separator}{index}for slot recipes), and itsCSS is hashed and persisted in
sharedStateunder a reserved__compoundvariant key.
StyleEncoderno longer dumps compound CSS into the atomic bucket; ithashes a
__compoundvariant entry per matching compound, which the ruleprocessor renders into
@layer recipes.createReciperuntime joins compound variant class names(
getCompoundVariantClassNames) instead of re-running atomiccss()on thecompound CSS — smaller runtime output and consistent layer placement.
compoundIndexthroughgetSlotCompoundVariantso the same compound variant produces a stablesuffix across all slots.
💣 Is this a breaking change (Yes/No):
No, but it is a behaviour change visible in the generated CSS. The selectors
that previously emitted the compound variant declarations move from atomic
utility classes (e.g.
.bg_red\.50) in@layer utilitiesto recipe classes(e.g.
.button--compound_0) in@layer recipes. Public APIs (cva,defineRecipe,defineSlotRecipe) are unchanged, and users do not authorthese class names by hand. Bumped as a
minorfor the three affectedpackages (
@pandacss/core,@pandacss/generator,@pandacss/shared).Atomic recipes are unchanged.
📝 Additional Information
Out of scope. Discussion #3493 also asks for user-supplied
classNameoncompound variants. That is deliberately not implemented here to keep this PR
focused. This PR lays the groundwork by giving every compound variant a
generated class name; a follow-up can let users opt to supply their own.
Tests.
packages/core/__tests__/recipe.test.tscoverdeclaration-order emission, non-matching filtering, array variant values,
and slot recipes.
static-css.test.ts,style-encoder.test.ts,generate-recipe.test.ts, andslots.test.tsreflect the new layerplacement and
compoundIndexpropagation.