Skip to content

refactor(useScheme): name the concept scheme, not schema - #1372

Merged
tenphi merged 1 commit into
mainfrom
revert-schema-to-scheme
Aug 27, 2026
Merged

refactor(useScheme): name the concept scheme, not schema#1372
tenphi merged 1 commit into
mainfrom
revert-schema-to-scheme

Conversation

@tenphi

@tenphi tenphi commented Aug 27, 2026

Copy link
Copy Markdown
Member

Reverts the schemeschema rename shipped in 0.170.0 (#1362), and renames the <html> attribute it was built to agree with.

Why

schema is the wrong word for this concept, on two counts:

  1. The platform calls it a scheme. prefers-color-scheme, the color-scheme CSS property, <meta name="color-scheme">. "Schema" means a structure definition.
  2. In Cube, "schema" means the data model. Cloud already has a useSchema() (SQL Runner), plus useSchemaPath(), useSchemaGenerationContext() and resolveSchemaLanguageExtensions(). A ui-kit useSchema() that returns 'light' | 'dark' is a pure homonym sitting in the middle of the product's core vocabulary — and Cloud's own name for the color concept is useResolvedScheme.

data-schema is the older half of the mistake — it predates #1362 (back to c12660be). #1362 propagated it into the API instead of fixing it; this PR fixes both halves at once.

Timing

Cheapest it will ever be. @cube-dev/ui-kit is at 0.171.0 and every Cloud package is pinned to 0.165.0, so nothing downstream has consumed the rename. Today this costs one PR here and nothing there. Once Cloud upgrades past 0.170, the same fix costs two migrations instead of zero.

The four new hooks are free: useSchema() has existed for two days and useScheme() never shipped, so renaming them back is invisible to everyone.

What changed

API, back to scheme:

  • renderColorTokens() / renderPaletteTokens() / RenderPaletteOptions: schema option → scheme
  • <CubeLogo> / <CubeFullLogo>: schema prop → scheme
  • useSchema()useScheme(), resolveSchema()resolveScheme(), subscribeSchema()subscribeScheme(), ColorSchemaColorScheme (useHighContrast() / resolveHighContrast() unchanged)
  • probe tokenOptions.schema.scheme; CLI --schema--scheme (--scheme hc still means light + high contrast)

DOM opt-in, renamed for the first time:

  • <html data-schema="dark"><html data-scheme="dark">; the tasty state is @root(scheme=…), so @dark compiles to :root[data-scheme="dark"]. data-contrast unchanged.

No aliases — and why the attribute doesn't get one

An alias for the attribute looked obviously worth it, so I measured it. Teaching @dark to accept both spellings works (the DSL handles the full precedence: canonical wins, then legacy, then the media query), but it expands every arm against both attributes. On a four-variant palette style map — the shape the palette actually emits:

@dark definition rules selector + declaration bytes
single attribute 21 3,602
both spellings 52 10,320

2.5× the rules and 2.9× the bytes on the kit's most-used state, permanently, to save a one-line edit in the one app that sets the attribute — and right after #1344 went to the trouble of batching stylesheet writes. The other shape, mirroring the legacy attribute onto the canonical one at runtime from Root, is free in CSS but puts permanent attribute-writing machinery in the library and has an SSR flash caveat.

Neither is worth it. An app that wants a transition window can write both attributes itself, for as long as it needs, at no cost to anyone else.

Migration for Cloud

Whenever it takes the upgrade, in packages/console-ui:

  • src/styles/theme.tsx — the three data-schema reads/writes → data-scheme
  • src/contexts/CubeSystemContext.tsxscopeToWarmUp entry
  • src/styles/adaptive-color.ts, src/codemirror/core/theme.ts — selector + comment references
  • tests/probe/harness.browser.probe.tsx — the two setAttribute calls
  • any hand-written CSS selecting [data-schema]

Cloud's own scheme naming (useResolvedScheme, adaptive-color.ts) already matches the reverted API, so nothing there has to be renamed — only the attribute.

Verification

  • vitest run — 102 files, 2202 passed, 1 skipped
  • tsc --noEmit — 18 errors, byte-identical to the count on main; none scheme-related
  • oxlint / prettier --check — clean (warnings on main unchanged)

Mechanical apart from the attribute decision: 64 files, 494 insertions / 494 deletions. $schema keys in JSON configs, the ESLint rule schema: field, and the genuine data-schema references in Tree docs/tests were excluded; prefers-color-scheme is untouched. src/icons/SchemeIcon.tsx is misnamed in the other direction (it's a sitemap glyph — really a data schema) and is left alone as a separate cleanup.

Chromatic

Four story exports are renamed, which changes their story IDs — PinnedScheme (CubeLogo), DarkScheme (NoDataIcon, LoadingAnimation) and ColorScheme (AdvancedStates). Chromatic will report four additions and four deletions rather than four unchanged stories, so expect approval prompts on snapshots that are identical to the baselines they replace.

🤖 Generated with Claude Code


Note

Medium Risk
Breaking rename of public hooks, token render options, logo props, probe flags, and the global data-scheme attribute affects every app that adopted 0.170.0’s schema spelling or data-schema; styling breaks if attributes are not migrated together.

Overview
Breaking rename that undoes the 0.170.0 schema terminology and aligns with platform vocabulary (prefers-color-scheme, color-scheme) and Cube’s data-model meaning of “schema.”

Public API goes back to scheme: renderColorTokens / renderPaletteTokens options, <CubeLogo> / <CubeFullLogo> props, and the hooks/types from 0.170.0 (useScheme, resolveScheme, subscribeScheme, ColorScheme; high-contrast helpers unchanged). The pnpm probe CLI and harness use --scheme and tokenOptions.scheme instead of --schema.

The document opt-in moves from <html data-schema> to data-scheme, with Glaze’s @dark state compiled against @root(scheme=…). Storybook bridges/decorators (colorSchemeBridge, withColorScheme, withDarkScheme) and docs/tests are updated to match; no backward-compat aliases on API or attributes.

Consumers must rename call sites, setAttribute('data-scheme', …), and any [data-schema] CSS.

Reviewed by Cursor Bugbot for commit 9f02b7f. Bugbot is set up for automated code reviews on this repo. Configure here.

`schema` was the wrong word. The platform calls this a color *scheme* —
`prefers-color-scheme`, the `color-scheme` property, `<meta
name="color-scheme">` — and in Cube's own vocabulary "schema" means the
data model, so a `useSchema()` returning `'light' | 'dark'` lands next to
Cloud's SQL Runner `useSchema()` as a pure homonym.

This reverts the API rename shipped in 0.170.0 (#1362) and also renames
the `<html>` attribute it was built to agree with: `data-schema` becomes
`data-scheme`, so `@root(scheme=…)` and `@dark` compile to
`:root[data-scheme="dark"]`. The attribute was the older half of the
mistake; #1362 propagated it into the API rather than fixing it.

No aliases. An alias for the attribute was measured and rejected:
teaching `@dark` to accept both spellings expands every arm against both
attributes, taking a four-variant palette style map from 21 rules /
3.6 KB to 52 rules / 10.3 KB — a permanent 2.9x on the kit's most-used
state to save a one-line edit in the one app that sets it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cube-ui-kit Ready Ready Preview Aug 27, 2026 1:24pm

Request Review

@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9f02b7f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cube-dev/ui-kit Minor

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

@github-actions

Copy link
Copy Markdown
Contributor

📦 NPM canary release

Deployed canary version 0.0.0-canary-eb9133b.

@github-actions

Copy link
Copy Markdown
Contributor

🏋️ Size limit report

Name Size Passed?
All 500.38 KB (-0.01% 🔽👏) Yes 🎉
Tree shaking (just a Button) 118.96 KB (0% 🟰) Yes 🎉

Compared against main at ae2b2d1run 33067377179, 2026-08-27T11:26:30Z.

To see which modules changed, download the size-limit-statoscope-report artifact from this run and open report.html.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Storybook is successfully deployed!

@tenphi
tenphi merged commit 7f1f722 into main Aug 27, 2026
16 checks passed
@tenphi
tenphi deleted the revert-schema-to-scheme branch August 27, 2026 14:02
@tenphi tenphi mentioned this pull request Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant