Skip to content

Component styling: Panda config recipes vs. cva / sva #85

Closed

Description

@ROBJkE

@fyrst/ui 0.5.0 keeps component styles as atomic cva / sva definitions. During the 0.5.0 work we also built the alternative, Panda config recipes, all the way through (commit 39b99f0), measured both against 0.4.1, and then reverted to cva / sva (commit 9d05491). This discussion records what we learned, so the decision can be revisited with data instead of from scratch.

TL;DR. Config recipes give app-wide theming, readable class names, override precedence by cascade layer, and generated variants. They also rename every component class, need staticCss, and come with a layering trap that caused two real regressions. cva / sva keeps today's class names and the 0.4.x mental model, at the cost of runtime style merging, some Panda warnings, hand-written variant scales, and no app-level extension point.


1. The two models, as they apply to this repo

cva / sva (current, 0.5.0)

  • Each component has a styles.ts with a static cva (one element) or sva (slots) definition.
  • panda lib publishes the package; apps set designSystem: '@fyrst/ui'. Panda extracts every cva / sva definition from the published JS and generates atomic classes for every variant (d_inline_flex, bg-c_primary, w_37%, …).
  • Overrides: every component takes css: CssMap<slots>. withCss(styles.raw(variants).slot, override) calls css(style, override), merging the objects so each property ends up with one class and the override wins.

Config recipes (built in 39b99f0, reverted)

  • Recipes (fyButton, fyAlert, …) lived in packages/preset/src/recipes/ and were registered by a library-only componentsPreset. panda lib bundled it into dist/panda/preset.mjs, so designSystem apps received it. The token-only @fyrst/ui/design-preset stayed recipe-free.
  • Components imported the generated runtime (@fyrst/ui/recipes) and got class strings such as fy-button fy-button--size_md fy-button--color_primary.
  • Overrides: withCss(recipeClass, override) appended css(override). Recipe CSS sits in Panda's recipes layer and overrides in utilities, so the override wins by layer order without merging objects.

2. What we measured

All numbers come from this repo at 0.4.1 / 0.5.0, a packed tarball installed into a minimal designSystem consumer, and the Nuxt playground.

Finding Detail
Config recipes need staticCss Variants come from props at runtime. Without staticCss, a packed consumer only got the default variant (.fy-badge, .fy-badge--size_md). With staticCss: { recipes: { fyBadge: ['*'] } } on the preset, every variant was generated.
No tree-shaking today, either way With the current atomic setup, a consumer that imports only BadgeRoot already gets Progress's w_37%. CSS output was 53,244 bytes both for "Badge only" and "import everything". So staticCss does not grow app CSS today. It would block tree-shaking per component later.
Apps can extend recipes theme.extend.recipes.fyButton.variants.size.xl in the app's config was merged over the library's recipe (fy-button--size_xl generated). Panda logs design_system_artifact_conflict as a reminder. A new variant value is not in the component's prop types, so it is only usable through the app's own recipe call.
Layering trap Panda emits recipe base styles in a lower sub-layer (@layer recipes { @layer base { … } }) than variants. (1) A variant beats any base state selector regardless of specificity: indeterminate Progress bars rendered at 0 px because percent_0 beat [data-state="indeterminate"]. (2) For !important the order inverts: a base _focus border beat the valid=false border, so a focused invalid field showed the primary border instead of red. Both were only caught by a computed-style diff against 0.4.1, not by unit tests. We added a guard test for this.
Visual parity After those fixes, both implementations matched 0.4.1 on 12 playground pages (dark and light, 19 computed properties per element, plus field rest / hover / focus states). The only differences were intentional (helper-text color, PricingCard overrides that now apply).
Panda warnings 0.4.1: 50 (41 panda_call_unextractable, 9 imported_recipe_raw_dynamic). Config recipes: 2. cva / sva in 0.5.0: 14 (12 imported_recipe_raw_dynamic, 2 panda_call_unextractable). The remaining imported_recipe_raw_dynamic warnings disappear when .raw() is called next to the definition (verified on Badge); not done yet, to keep one pattern.
Override extraction In both models, an app's css value is only generated when written as css.raw({…}). A bare object literal compiles and type-checks but produces no CSS. The 0.4.x playground had several such no-op overrides.
Static extraction limits cva / sva must be static literals, so Progress keeps 101 hand-written percent variants, Loader 11 sizes, and Card 9 border widths. A preset runs as code, so recipes generated them with Object.fromEntries (Progress styles.ts: ~600 → ~100 lines).

3. Pros and cons

Config recipes

Pros

  1. App-wide theming without forking. Apps can change a component globally in their own panda.config.ts (theme.extend.recipes.fyButton). With cva / sva the only lever is a per-instance css override or global CSS against atomic classes.
  2. Override precedence by layer, not by merge. utilities always beats recipes, so overrides are a cheap class append. No style objects are merged at runtime per render.
  3. Readable, stable class names. .fy-button--size_md and .fy-alert__root work as test selectors, in devtools, and as hooks for consumer CSS. Atomic names say nothing about which component they belong to.
  4. Generated variants. Repetitive scales are code, not 100+ lines of literals.
  5. Fewer build warnings (2 vs 14), so a real extraction problem is easier to spot.
  6. Generated variant types (FyButtonVariantProps) from Panda's codegen.

Cons

  1. Breaking for consumers. Every component class name changes: snapshots, e2e selectors, and any app CSS that targets library classes break. For an 0.x library with few consumers that is manageable; it gets more expensive every release.
  2. The base sub-layer trap. Variants silently outrank base state selectors, and base !important silently outranks variants. Both bit us. Every new recipe has to respect this; a guard test helps but does not catch everything (it checks for overlaps, not for intent).
  3. staticCss is mandatory for a design system whose variants come from props. That emits every variant into every app forever and closes the door on per-component tree-shaking.
  4. Shared recipe namespace. Library recipes live in the app's recipe namespace (fy* prefix). An app recipe with the same key merges into the library's.
  5. Styles move away from components (into the preset package), and the preset must be split (token-only vs. components) so token-only apps do not inherit component CSS.
  6. Not obviously smaller CSS. Recipe classes carry full declarations per variant; atomic classes are shared across components. We did not measure the full-library CSS size difference; it should be measured before deciding.
  7. Extension is only half typed. App-added variant values generate CSS but are not accepted by the Vue component's props.

cva / sva

Pros

  1. No class-name churn. 0.5.0 keeps 0.4.x atomic classes, apart from colors that now use semantic tokens. The migration for apps stays small.
  2. Predictable cascade. Everything is atomic in the utilities layer; no hidden sub-layers. The 0.4.1 behavior (focus/hover on invalid fields, indeterminate Progress) holds with no special cases.
  3. Colocation. styles.ts sits next to the component that uses it.
  4. Atomic output dedups across components (same property/value = same class).
  5. Proven with panda lib / designSystem since 0.3.0, including the stale-buildinfo re-extraction fallback.

Cons

  1. No app-level extension point. Global theming of a component means a css override on every instance, or global CSS against atomic classes.
  2. Overrides need runtime merging. withCss must merge style objects (css(style, override)); appending a class would leave two competing atomic classes and let stylesheet order decide. This costs a little at runtime and must not be "simplified" (a test guards it).
  3. imported_recipe_raw_dynamic warnings (12) unless .raw() moves into helpers next to each definition.
  4. Static literals only. Variant scales are written out by hand.
  5. Unreadable class names for tests and debugging.

4. Side-by-side

Config recipes cva / sva
Class names fy-button--size_md (semantic) bg-c_primary, w_37% (atomic)
Change vs 0.4.x for apps every component class only token-based colors
App-wide theming theme.extend.recipes.* not possible (per-instance css, or global CSS)
Per-instance overrides append class; wins by layer merge objects (css(style, override))
Variant CSS generation needs staticCss automatic from the definition
Per-component tree-shaking later blocked by staticCss possible in principle (not today)
Layering pitfalls base sub-layer (2 regressions found) none found
Generated variants yes no (static literals)
Panda warnings 2 14 (12 avoidable)
Where styles live preset package next to each component
Token-only preset needs a separate components preset unaffected

5. Options

  • A. Stay on cva / sva (current). Optional follow-ups: move .raw() into helpers in each styles.ts to drop the 12 warnings; add a data-part / stable class hook for tests if needed.
  • B. Move to config recipes (the 39b99f0 implementation exists and passes the full test suite plus the visual diff). Ship it with the guard test for the layering trap, the migration notes for class names, and a measured CSS size comparison.
  • C. Hybrid. Keep cva / sva, and expose config recipes only for the few components apps most want to theme globally (Button, Field controls, Card). Two patterns in one codebase is the cost.
  • D. Defer to 1.0. Collect consumer feedback on theming needs and class-name dependencies first; decide when the public contract is frozen.

6. Questions for maintainers and consumers

  1. Do apps need global component theming (radius, sizes, colors per brand), or are per-instance css overrides enough?
  2. Does any consumer rely on atomic class names (tests, snapshots, global CSS)? How costly would renaming be?
  3. Is per-component tree-shaking a goal? If so, staticCss (required by config recipes) works against it.
  4. Should we measure full-library CSS size for both models before deciding?
  5. If we switch later, should it be in a minor (0.x) or wait for 1.0?

Reference commits on branch ccr-51512907-w98cka: 39b99f0 (config recipes), 9d05491 (back to cva / sva, current). Background: changelog/2026-10-31-0.5.0-overrides-and-cleanup.md.

Activity

  1. locked and limited conversation to collaborators on Oct 31, 2026
  2. converted this issue into a discussion #87 on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions