Skip to content

Discussion: Theme Builder experience report — building with XDS #155

Closed

Description

@cixzhang

Context

We built an interactive theme builder as a consuming project to test the XDS source distribution workflow end-to-end. The goal was to understand what it's like to build a real app with XDS — from installation to creating proper StyleX themes.

Initial prompt

Build a theme builder with a lightweight UI that lets me pick colors for each public CSS color token, set radius values, and use a single unit input that scales all spacing/sizes. Show a good set of demo components in the middle (card with layout, table, buttons, inputs — like a todo list). All controls should use XDS components. Support saving themes to localStorage, switching between them, and exporting valid XDS theme files. Start with neutral wireframe defaults. Changes should not apply immediately — use an Apply button with a brush sweep animation.

Sample themes created

Default, Wireframe, Meta AI (inspired by Meta AI branding), Midnight (dark), Warm Earth (organic tones), Brutalist (zero radius, black borders, hot pink accent).


What went well

  1. Source distribution packaging works. yarn package:source → npm pack → npm install ./tarball installed @xds/core into node_modules with raw source. Components imported and compiled cleanly.

  2. StyleX compilation at the app level works. Both the PostCSS path (Next.js) and the babel plugin correctly compiled XDS component styles alongside app styles. The 42KB extracted CSS included all tokens, atomic classes, and theme variants.

  3. Component API is solid. Building the todo list demo (XDSButton, XDSTextInput, XDSCheckboxInput, XDSCard, XDSVStack/XDSHStack, XDSBadge, XDSDivider, XDSHeading/XDSText, XDSLayout) felt natural. The components composed well together.

  4. XDSLayout is good. Header/Panel/Content slots with hasDivider, isScrollable, and width props made the sidebar layout clean.

  5. Theme switching with XDSTheme provider works. Once the themes were proper createTheme objects, switching between them via the provider was instant and correct.

  6. Creating proper StyleX themes is doable. The pattern of createTheme(colorVars, colorRaw) for each token group, assembled into a Theme object, works well once you know the shape.


Hiccups and gaps

1. Import resolution for createTheme across packages is the hardest part

This was the single biggest friction point. createTheme() requires StyleX to statically resolve the original defineVars() call. When theme files in the consuming project import tokens via @xds/core/theme/tokens.stylex, the StyleX babel plugin needs aliases configured to find the source:

aliases: {
  '@xds/core/*': [path.join(rootDir, 'node_modules/@xds/core/*')],
  '@xds/core':   [path.join(rootDir, 'node_modules/@xds/core')],
}

Without this, you get a cryptic nonStaticValue error from the babel plugin. This needs to be prominently documented — it's not obvious and the error message doesn't suggest the fix. Even knowing it was an aliases issue, getting the exact config right took multiple attempts.

Recommendation: The package-source.js script or CLI init command should generate a starter babel.config.js with the correct aliases pre-configured.

2. PostCSS setup has silent failure modes

  • The @stylex; at-rule in the CSS file is required for the PostCSS plugin to extract styles. Without it, PostCSS produces an empty CSS file with no error or warning. This cost debugging time.
  • The include pattern must explicitly cover node_modules/@xds/core/** — PostCSS only scans app source by default.

Recommendation: Add validation or warnings when the PostCSS plugin finds no StyleX rules to extract.

3. 'use client' boundary needed for XDSTheme

XDS components use createContext but don't include 'use client' directives. In Next.js App Router, the theme provider needs to be wrapped in a client component. This is a known pattern but should be documented in the setup guide.

4. Color editing UX needs work

  • Too many individual color pickers. 50+ color tokens is overwhelming. Setting them one by one is tedious and it's hard to create a cohesive palette.
  • No light/dark mode support. XDS tokens use light-dark() but the builder only sets single values. Setting both light and dark values would double the already-large number of inputs.
  • Recommendation: A "derive from palette" approach where you pick 3-5 key colors (accent, surface, text, positive, negative) and the builder derives the full token set (deemphasized variants, icon colors, divider colors, etc.) would be much more practical.

5. Default appearance is too gray/flat

The wireframe starting point renders everything in neutral grays, which makes the initial experience feel broken rather than intentionally minimal. Primary buttons appear as gray solid fills rather than outlined/ghost — losing the wireframe aesthetic.

Recommendation: Wireframe defaults should use outlined/ghost styling for primary actions, and the overall feel should look more like a deliberate wireframe than a broken theme.

6. LightningCSS polyfills light-dark()

Vite's LightningCSS transformer lowers light-dark() into --lightningcss-light/--lightningcss-dark custom properties when targeting older browsers. This creates unexpected CSS output. Fixed by setting explicit CSS targets in the Vite config (Chrome 123+, Firefox 120+, Safari 17.5+).

7. Input components need CSS resets

Input containers were missing box-sizing: border-box, causing overflow when padding was applied. Inner <input> elements in some components showed browser default borders. (Fixed in PR #152.)

8. The brush sweep animation added complexity

The reveal animation was a fun idea but made the apply flow harder to debug. The boolean trigger pattern caused stale closure issues (fixed by switching to a counter). The animation itself is subtle enough that it's easy to miss — unclear if it's worth the complexity.

9. Theme builder still has issues

The theme builder is not fully working yet — there are remaining bugs with theme application and the overall flow needs more polish before it's usable as a standalone tool.


Where human intervention was necessary

  1. Identifying the PostCSS requirement. The initial setup used @stylexjs/nextjs-plugin (webpack path) which worked but the StyleX team recommends the PostCSS path for Next.js. Human pointed to the StyleX example-nextjs as the reference.

  2. Aliases config for cross-package createTheme. The LLM tried relative paths, different import patterns, and various workarounds before the human confirmed "use aliases config" — which is what the StyleX team had suggested.

  3. Architecture decisions. Human directed: use proper StyleX themes (not CSS var objects), use XDSTheme provider (not manual style injection), remove the card border gradient hack (it should be part of the theme, not a separate control).

  4. Debugging theme application. The LLM's initial brush sweep implementation had stale closure bugs. The human had to report that "apply isn't working" and "background always appears white" — the LLM couldn't test the runtime behavior.

  5. Repo access. The XDS repo name (facebookexperimental/xds) took a few tries to get right.


Missing features / future work

  1. "Derive from palette" color input — Pick 3-5 key colors, auto-derive the full 50+ token set. This is the biggest UX improvement needed.

  2. Light + dark mode editing — Currently only sets single values. Need a way to set both halves of light-dark().

  3. Live preview without Apply — Optional instant preview mode (in addition to the deliberate Apply flow) would speed up iteration.

  4. Component style overrides — The theme builder only handles token values. XDS themes can also override component-specific styles (button variants, heading styles, etc.). The builder should support this.

  5. Integration with XDS docs site — This should eventually live on the XDS documentation site as an interactive theme creation tool.

  6. Better error messages for StyleX config issues — The silent failures and cryptic errors around createTheme resolution need better DX.

  7. Starter config generation — The CLI init command or package-source.js should generate correct babel/postcss configs with aliases pre-configured for the consumer's bundler.


Related

Activity

  1. added
    documentation
    on Feb 19, 2026
  2. cixzhang commented on Feb 19, 2026

    @cixzhang
    ContributorAuthor

    Addendum: LLM component discovery gaps

    XDSLayout wasn't reached for initially

    The theme builder's page layout was initially built with manual flexbox (a raw div with display: flex, hardcoded sidebar width, manual overflow/padding). The human had to explicitly ask "can you use an XDSLayout?" — at which point it was an obvious fit (XDSLayout with XDSLayoutHeader, XDSLayoutPanel, XDSLayoutContent slots).

    Why it was missed: The LLM treated the page shell as scaffolding around XDS components rather than something that should be built with XDS components. XDSLayout was mentally categorized as a "content layout" tool rather than an "app shell" tool, even though the header/panel/content slot pattern is exactly an app shell.

    This is a component discovery problem. The LLM had access to the component source and could see the exports, but didn't connect "I need a sidebar layout" → "XDSLayout has a start panel slot." Better component documentation, usage examples, or naming could help here.

    CLI + agent docs flow was not tested

    Notably, we did not use the xds init or xds agent-docs CLI flow in this round. The LLM was working from raw source code and grep — no AGENTS.md guidance, no component documentation installed, no structured API reference.

    This is worth comparing in a future session where we:

    1. Run xds init to set up the project
    2. Run xds agent-docs to install the AGENTS.md with component guidance
    3. See if the LLM makes better component choices (like reaching for XDSLayout immediately)

    The hypothesis is that the agent docs — which include component descriptions, prop tables, and usage patterns — would have surfaced XDSLayout as the right tool for the job without human intervention. This session serves as the baseline without agent docs for that comparison.

  3. cixzhang commented on Feb 19, 2026

    @cixzhang
    ContributorAuthor

    Wash background didn't apply

    The theme builder's page background was supposed to use --color-wash but stayed white regardless of the theme. This went through several failed attempts:

    1. backgroundColor: 'var(--color-wash)' in an inline style alongside the CSS custom property definitions — the var reference didn't resolve because React inline styles don't guarantee CSS custom property resolution order on the same element.

    2. Reading the value directly (appliedVars['--color-wash']) — worked for the CSS var override path but not when using XDSTheme provider (where the wash color is set via StyleX classes, not inline vars).

    The root issue: XDSTheme uses display: contents and doesn't create a visual box, so it can't carry a background color. The theme sets --color-wash as a CSS variable but nothing in the XDS system actually applies it as a background. Consumers are expected to set their own background-color: var(--color-wash) somewhere — but this isn't documented and isn't obvious.

    This is a gap in the theme system. A common expectation is that wrapping your app in <XDSTheme> gives you a fully themed page, including the background. Options:

    1. XDSTheme could optionally render a wrapper div with backgroundColor: var(--color-wash) (opt-in via prop)
    2. XDSLayout could apply wash as its background by default
    3. Document that consumers need to set their own page background

    This tripped up both the LLM and the human — it's a real DX gap, not just an LLM discovery problem.

  4. cixzhang commented on Feb 19, 2026

    @cixzhang
    ContributorAuthor

    Component style overrides are hard for LLMs to discover

    The XDS theme system supports component-level style overrides via module augmentation:

    // In XDSCard.tsx
    declare module '../../theme/types' {
      interface ComponentStyles {
        card?: {
          container?: ThemeStyleXStyles;
          content?: ThemeStyleXStyles;
        };
      }
    }

    Then in a theme:

    const cardStyles = stylex.create({
      container: {
        borderImage: 'linear-gradient(135deg, #00D2FF, #0668E1, #7B61FF) 1',
      },
    });
    
    export const myTheme: Theme = {
      // ...styles, raw...
      components: {
        card: { container: cardStyles.container },
      } as Theme['components'],
    };

    Why this is hard for LLMs:

    1. The pattern is unusual. Module augmentation to extend an interface across files isn't a common React pattern. LLMs default to wrapper components, CSS var hacks, or inline styles instead.

    2. Discovery requires cross-file reading. You need to find the declare module in the component source, understand the augmentation target, then look at how existing themes use it. There's no single place that says "here's how to style cards in a theme."

    3. The as Theme['components'] assertion is a red flag. It signals that the type system can't fully verify this, which makes LLMs less confident about using it.

    What happened: When asked for rainbow gradient borders on Meta AI cards, the LLM created a ThemedCard wrapper component that manually applied CSS vars for gradient borders — completely bypassing the theme system. The human had to explicitly say "we shouldn't need to do that" and point back to proper theme component overrides.

    What could help:

    • A "How to create a theme" guide that explicitly covers component overrides with examples
    • Agent docs (AGENTS.md) that list each component's themeable properties
    • A xds theme scaffold CLI command that generates a theme file template with all component override slots commented out
    • Better naming — ComponentStyles augmentation is invisible unless you know to look for declare module
  5. cixzhang commented on Feb 19, 2026

    @cixzhang
    ContributorAuthor

    On discoverability: retrieval over directives

    The XDSLayout source was in the LLM's context window — it had read the component files and seen the slot-based API, padding management, and scroll containment. But it didn't connect "my layout has weird spacing" → "XDSLayout exists for this."

    What wouldn't help: Adding "always use XDSLayout for page layouts" to the docs. This creates a tragedy of the commons — if every component says "always use me," the urgency becomes noise and LLMs learn to ignore it.

    What would help: Making the connection discoverable through retrieval-based reasoning:

    1. Use-case-oriented descriptions — "XDSLayout — Page shell with header, sidebar, and content slots. Manages padding collapse, scroll containment, and responsive slot sizing." This lets the LLM match its problem ("I need a sidebar with proper padding") to the component.

    2. Decision trees in agent docs — "Building a page with a sidebar? → XDSLayout. Stacking items vertically? → XDSVStack. Need a scrollable content area? → XDSLayoutContent." This is retrieval-friendly — the LLM searches for its problem and finds the answer.

    3. Full-page examples — Component docs that show XDSLayout in a complete page context (not just the component in isolation). When the LLM thinks "I need a sidebar layout," retrieval pulls up the example.

    This scales better than directive-based docs because the LLM looks up what it needs when it needs it, rather than trying to hold every rule in working memory.

  6. cixzhang commented on Feb 19, 2026

    @cixzhang
    ContributorAuthor

    Comparison: XDS components vs raw HTML + StyleX

    We built the same theme builder twice — once with XDS components, once with raw HTML + StyleX only — to compare the experience and output.

    Bundle size

                            Page JS    Shared chunks    Total
    XDS version             24.5 KB    58.6 KB          83.1 KB
    Raw version             34.4 KB    0 KB             34.4 KB
    Difference                                          +48.7 KB (2.4x)
    

    Tree-shaking works correctly — only imported components and their dependencies are bundled. The 58.6KB comes from:

    Chunk Components Size
    532 XDSTextInput, XDSField/FieldLabel/FieldStatus, XDSLayout/Panel/Content/Header, XDSTheme, XDSCheckboxInput, XDSIcon, XDSCard 30.6 KB
    585 XDSButton, XDSText, XDSHeading, XDSHStack, XDSVStack, XDSBadge, XDSDivider, XDSSpinner, XDSTooltip + layer system 28.1 KB

    Of that 58.6KB, ~26KB (44%) could be lazy-loaded — the tooltip/layer system (12.2KB), field system (8KB), spinner (2.7KB), and icon (3.1KB) are pulled in as dependencies even when their features aren't used. See #157 for the tooltip analysis.

    Code volume

                            Lines of code
    XDS version             ~800 lines (app code only)
    Raw version             ~1,413 lines
    Difference              +613 lines (77% more)
    

    The raw version has to style every button, input, card, badge, table, and layout from scratch. The XDS version reuses all of that.

    Setup complexity

    XDS version Raw version
    babel.config.js Required (with aliases) Required
    postcss.config.js Required (scan node_modules) Not needed
    @stylex directive Required in CSS file Not needed
    transpilePackages Required Not needed
    Aliases config Required for createTheme Not needed
    Total config files 4 1

    The raw version built on the first try. The XDS version required debugging PostCSS config, aliases, @stylex; directive, and 'use client' boundaries.

    Development experience

    XDS version Raw version
    Time to first build ~45 min (config debugging) ~5 min
    Component discovery Required reading source N/A (wrote everything)
    Missed XDSLayout Yes (used manual flexbox first) N/A
    Accessibility Built-in (aria, focus management) Manual (minimal)
    Theme integration XDSTheme provider + createTheme Just CSS vars
    Consistency Guaranteed by design system Developer's responsibility

    Key takeaway

    The raw version is faster to set up and produces a smaller bundle, but requires significantly more code and provides no accessibility, consistency, or theme system guarantees. The XDS version's setup friction is almost entirely from the source distribution model (PostCSS, aliases, transpilePackages) — not from the components themselves. If that setup were smoother (e.g., a CLI that generates the config), the XDS version would be strictly better.

    Repos

  7. cixzhang commented on Feb 20, 2026

    @cixzhang
    ContributorAuthor

    Feedback on theme-builder-raw

    Tried out the raw version — it looks quite good, actually better than the first iteration with XDS.

    The LLM did well covering the major, larger areas like layout but did worse on smaller details like input and button relative sizing.

    This is an interesting signal for the comparison: the raw version gives the LLM more direct control over every detail, but it still struggles with the finer points of visual consistency (relative sizing between inputs and buttons, proportional spacing). These are exactly the things a design system is supposed to handle for you — which reinforces the value proposition of XDS even as the raw version "looks better" at a glance.

  8. cixzhang commented on Feb 20, 2026

    @cixzhang
    ContributorAuthor

    For posterity, here's a set of screenshots:

    | Using XDS (initial state) | Image |
    | Using XDS (after XDSLayout refinement) | Image |
    | Raw HTML + stylex | Image |

  9. cixzhang commented on Feb 20, 2026

    @cixzhang
    ContributorAuthor

    We will attempt again after our refinements have landed tonight.

  10. cixzhang commented on Feb 20, 2026

    @cixzhang
    ContributorAuthor

    Here's a screenshot of the second attempt after day 1 fixes.

    Image

    It's much improved. There are still some hiccups related to the LLM's understanding of our layouts and built-in paddings/scrollable areas to work through.

  11. cixzhang commented on Feb 20, 2026

    @cixzhang
    ContributorAuthor

    Theme Builder v2 — experience report

    Re-attempted the theme builder exercise after landing doc improvements from today's session. Built on cixzhang/xds_sandbox@theme-builder-v2.

    What improved

    1. XDSLayout was reached for immediately. The LLM used XDSLayout for the page shell without prompting — the updated @position tags and "When to use" decision tree worked. No manual flexbox for the page structure.

    2. XDSTopNav went directly in the header slot. The new docs showing TopNav composing without an XDSLayoutHeader wrapper were picked up correctly. No isFullBleed or hasDivider={false} overrides needed.

    3. "Derive from palette" approach was used. The LLM built 8 key color inputs that derive the full ~80 token set, rather than showing all 80 individually. This was one of the v1 recommendations.

    4. Overall layout quality is much better compared to the first iteration with XDS. The page shell structure (header + sidebar + content) was correct from the start.

    What still tripped up

    1. Double padding and scrollbars. The LLM added paddingInline, paddingBlock, and overflowY: 'auto' to components inside XDSLayoutPanel and XDSLayoutContent, not realizing these slots already provide their own padding and scroll containment. This caused doubled spacing and nested scrollbars.

    2. 20 missing subpath exports in the tarball. The LLM correctly used subpath imports like @xds/core/TopNav, @xds/core/Slider, etc. — but they weren't in the package.json exports map. The package-source.js script only mapped exports already in packages/core/package.json, missing components like TopNav, TabList, Slider, Switch, NumberInput, RadioList, Table, StatusDot, and 12 others.

    3. Input/button relative sizing still weak. Same observation as the raw version — the LLM does well on layout structure but struggles with finer details like relative sizing between inputs and buttons. The button showcase in the side panel shows all sizes but they don't feel cohesive with the input sizing next to them.

    4. Stale localStorage crash. The hook loaded saved themes from localStorage without validating the data shape, causing a crash when old data from a previous session didn't match the expected SavedThemeEntry format.

    5. Sub-agent coordination gaps. The page.tsx referenced sweepCount from the hook, but the hook sub-agent didn't include it. The save() function signature ((name?: string) => void) was incompatible with onClick handler type. These are integration seams between independently-built modules.

    Comparison with v1

    v1 (original) v2 (after doc improvements)
    Used XDSLayout No — manual flexbox, human had to suggest it Yes — immediately
    TopNav in header slot N/A Yes — no wrapper
    Color approach 50+ individual pickers 8 key colors, derive the rest
    Double padding Not reported (different structure) Yes — didn't know slots provide padding
    Missing exports Different issue (aliases) 20 missing subpath exports
    Setup friction High (PostCSS, aliases, @stylex directive) Low (pre-configured)

    New issues filed

    Takeaway

    The use-case-oriented descriptions and decision trees measurably improved component selection — XDSLayout and XDSTopNav composition were correct from the start. The remaining gaps are about implicit behaviors (slots provide padding) rather than component discovery (which component to use). The fix pattern is the same: tell the LLM what it doesn't need to do, right where it'll read it.

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

    documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions