Skip to content

Simplify CSS variable system, add css-data.json for IDE/LLM support#4291

Draft
amcclain wants to merge 8 commits into
developfrom
css-var-simplify
Draft

Simplify CSS variable system, add css-data.json for IDE/LLM support#4291
amcclain wants to merge 8 commits into
developfrom
css-var-simplify

Conversation

@amcclain

@amcclain amcclain commented Mar 10, 2026

Copy link
Copy Markdown
Member

Summary

  • Removes the two-tier CSS custom property override system. Previously, Hoist defined framework variables like --xh-grid-bg: var(--grid-bg, var(--xh-bg)), where the unprefixed --grid-bg served as an app-level override hook. This added complexity, confused IDE autocomplete (apps were expected to set vars that didn't appear in any source), and was inconsistently applied across the codebase. Applications now override the --xh- prefixed variables directly - simpler, IDE-friendly, and consistent with modern CSS variable conventions.

  • Adds css-data.json for IDE autocomplete and LLM/agent consumption. A VS Code Custom Data file generated from vars.scss by bin/generate-css-data.mjs, providing autocomplete and hover documentation for all ~440 --xh-* CSS custom properties. Descriptions are auto-generated from variable name structure and value relationships (derivations, aliases, intent system, palette colors), with support for explicit /// doc comments that take precedence. A pre-commit hook validates the file stays in sync when SCSS files change; prepack regenerates before publish.

Motivation

The unprefixed override hooks were an unnecessary layer of indirection. Analysis of sample apps found only ~39% of the 265 hooks were ever used, and apps that did use them got no IDE support - the unprefixed names existed only inside var() fallback expressions in vars.scss, invisible to autocomplete. Meanwhile, the --xh- prefixed names were the ones actually documented and referenced in component SCSS. Removing the two-tier pattern and standardizing on --xh- eliminates confusion and makes the system work better with modern tooling.

The css-data.json file takes this further by giving VS Code users immediate autocomplete with descriptions, and - more importantly - giving coding agents and LLMs a machine-readable index of every available CSS variable with relationship and override guidance baked into the descriptions.

Breaking change

This is a low-difficulty mechanical migration for apps. Most overrides simply need an xh- prefix added. A small number of unprefixed names differed from their --xh- counterparts - the upgrade notes include a complete mapping table and grep commands for finding affected code.

See docs/upgrade-notes/v87-upgrade-notes.md for step-by-step instructions.

Originally drafted against v83; merged up to v87-SNAPSHOT. The intent text-color copy-paste bug fix that originally accompanied this work was merged separately and shipped in v83.0.0, so it is no longer part of this PR.

Test plan

  • Application loads without console errors in both light and dark themes
  • Custom colors, spacing, and typography render correctly after migrating overrides
  • css-data.json provides autocomplete in VS Code when configured via css.customData
  • Pre-commit hook blocks commits with stale css-data.json when SCSS is modified
  • node bin/generate-css-data.mjs --check passes after regeneration

amcclain and others added 5 commits March 9, 2026 09:24
…efix

Remove the unprefixed CSS variable override hooks (e.g. --grid-bg, --pad, --font-size) from vars.scss. Applications now override the --xh- prefixed variables directly. This eliminates unnecessary indirection, enables IDE autocomplete for override targets, and aligns with modern CSS variable conventions.

The previous system defined vars like `--xh-grid-bg: var(--grid-bg, var(--xh-bg))` where apps set the unprefixed `--grid-bg` to customize. After this change, `--xh-grid-bg: var(--xh-bg)` is the simplified form, and apps set `--xh-grid-bg` directly.

Also includes the intent text-color copy-paste bug fix from the prior commit and adds CHANGELOG and v83 upgrade notes documenting the migration path (mechanical find-and-replace for most apps, with a mapping table for the small number of naming mismatches).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove all references to the two-tier unprefixed override pattern. Update examples to use --xh- prefixed variables directly, add scoped override and dark theme override guidance, and revise pitfall examples accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Introduce bin/generate-css-data.mjs, which parses vars.scss to produce a VS Code Custom Data file (css-data.json) with descriptions for all ~425 --xh-* CSS custom properties. Descriptions are auto-generated from variable name structure and value relationships (derivations, aliases, intent system, palette colors), with support for explicit /// doc comments that take precedence. Added sample doc comments to key vars in vars.scss.

The generated file is checked in and ships with the npm package. A pre-commit hook validates it stays in sync when SCSS files change, and prepack regenerates it before publish.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@amcclain

amcclain commented Mar 10, 2026

Copy link
Copy Markdown
Member Author

We have a further option to also remove the indirection we have with unit-less values, then we then multiply to make varying combinations (e.g. --xh-pad vs --xh-pad-px). This could also be simplified out.

We should discuss if we want to make that change also, or if this is already pushed as far as we're comfortable.

I do like that this cleans up something that's been muddy in my mind from the very beginning and would love to get it merged when we're ready.

Feedback + thoughts appreciated!

Catch up with develop (v83 -> v87-SNAPSHOT). Conflict resolutions:

- styles/vars.scss: removed all two-tier override hooks (the PR's purpose),
  taking develop's newer underlying values and new vars (grid tooltip vars,
  --xh-bg-highlight-alt, --xh-loading-indicator-spinner-color, SegmentedControl,
  Spinner, dark button bg variants). Unwrapped var(--hook, INNER) -> INNER for
  every hook develop added in non-conflicting regions as well.
- docs/upgrade-notes/v83-upgrade-notes.md: kept develop's real v83 release notes;
  relocated the PR's CSS-variable migration notes to a new v87-upgrade-notes.md.
- CHANGELOG.md: PR entries now sit under 87.0.0-SNAPSHOT; fixed upgrade-notes link
  to v87, merged the duplicate Bug Fixes section, added difficulty description.
- css-data.json: regenerated against merged vars.scss (441 properties).
The intent text-color copy-paste bug (introduced in v80 by #4194) was fixed
independently in commit 428f3f6 and shipped in v83.0.0. It is already on
develop, so referencing it as a v87 fix in the changelog and upgrade notes was
misleading - removed both the changelog bullet and the upgrade-note section.
@amcclain amcclain added this to the v87 milestone Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant