Skip to content

spec(theme-tokens): spacing tokens are rem and follow the root font size - #7373

Merged
cixzhang merged 3 commits into
mainfrom
spec/spacing-tokens-rem
Oct 12, 2026
Merged

cixzhang merged 3 commits into
mainfrom
spec/spacing-tokens-rem

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Exact decision needed

Whether the core --spacing-* scale is rem (so gaps and padding follow the reader's root font size, as the type scale does) or stays fixed px, and what that means for themes that override spacing steps and for custom themes.

Existing authority searched

  • architecture:theme-tokens (current): names, roles, defaults, helpers, projections — no unit rule for spacing.
  • design:iconography (draft): icon sizes use rem so they scale with the root font size — the precedent for this decision.
  • Code: packages/core/src/theme/tokens.stylex.ts (spacing defaults in px), defineTheme (spacing only as per-step token overrides; no base-unit derivation), the first-party themes (matcha and y2k pin steps in px; the others inherit core), and the two generators: the CLI theme templates (verbatim copies of a source theme's steps) and the docsite playground theme editor (derives a ramp from a base step and exports defineTheme source).

Decision

Spacing tokens are rem (--spacing-N = N × 0.25rem; unchanged pixel values at the default root). A theme that overrides steps uses rem for the same reason; a px pin is that theme's documented exception; author-written values in custom themes are honoured as written. Non-CSS helpers return the rem string. Decided by the owner on 2026-10-12 (architecture:theme-tokens DEC-1), with the accepted costs recorded: fixed-width table columns at very large roots, matcha/y2k until they move to rem, and code that parses a spacing token as a pixel number.

Delta

  • docs/architecture/theme-tokens.md: INV9 (routed under the tokens trigger), a verification row, DEC-1.

Implementation: the open spacing-tokens pull request changes the core scale and the playground editor's generated ramp to rem; moving matcha's and y2k's pinned steps (package and CLI template copies) and the annotated theme template's '12px' spacing example to rem is its own small change behind this record.

Writing rubric results

  • R1 present tense, no narration: pass.
  • R2 research is an artifact: pass (the root-font-size measurements stay in the implementation pull request).
  • R3 evidence names facts: pass (the verification row names tests, not pull requests).
  • R4 rejected alternatives one line, inside the decision: pass (two).
  • R5 no pull-request or issue references: pass.
  • R6 open questions: none added.

Search terms: spacing rem, root font size, --spacing, spacingDefaults, rem-based across docs/, open and closed pull requests. Overlapping work: the open spacing-tokens implementation pull request (code only, no record change) and the merged icon-size precedent.

…me-tokens INV9, DEC-1)

Core spacing defaults are rem; a theme overriding steps uses rem for the same
reason, a px pin is that theme's documented exception, and author-written
values in custom themes are never converted. Spacing has no base-unit
derivation, so the only generator surface is the CLI's theme templates, which
copy a source theme's steps verbatim.
@vercel

vercel Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 12, 2026 1:22pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 12, 2026
@astracat-bot

astracat-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 12, 2026, 1:41 PM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 12, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec d415fd3

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 12, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds a new rule to a current spec record (INV9, DEC-1 and the INV9 verification row in architecture:theme-tokens), so approval needs a maintainer to adopt that rule with the points below in view. Independent of that decision, please fix these:

  • DEC-1 says only the CLI theme templates generate spacing values, but the docsite playground theme editor derives a px spacing ramp from a base step and exports it as defineTheme source.
  • INV9 says useTheme().token() and resolveThemeToken() return the rem string, but under a theme with a px pin (matcha's --spacing-4 is 24px) they return px, so describe the value by unit instead.
  • The INV9 row's failure signal, “a scaffolded theme emitting px steps”, flags the documented px exceptions INV9 allows, and today it also fails on the ejected matcha and y2k themes that DEC-1 accepts.
  • “the same pixel value as before” and “until they move to rem” in DEC-1 describe the change rather than the system, which the R1 rubric result missed.

[Automated review]

Comment thread docs/architecture/theme-tokens.md Outdated
Comment on lines +110 to +112
Non-CSS consumers (`useTheme().token()`, `resolveThemeToken()`,
`tokenDefaults`) return the `rem` string; code that needs pixels resolves it
against the root font size instead of parsing a number.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolveThemeToken() and useTheme().token() apply theme.tokens over tokenDefaults, so under a theme with a px pin (matcha's --spacing-4 is 24px) they return px, not rem. Suggested wording: they return the resolved string as written — rem for the core defaults, or the unit a theme sets — so code that needs pixels converts by unit instead of parsing a number.

Comment thread docs/architecture/theme-tokens.md Outdated

Spacing tokens are `rem`. A reader who raises the browser's root font size gets
proportionally larger gaps and padding, so text does not tighten inside boxes
that stayed in pixels; at the default 16px root every step is the same pixel

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“the same pixel value as before” describes the change rather than the system (rubric R1). Suggested: “at the default 16px root, --spacing-N computes to N × 4px”. “until they move to rem” a few lines down has the same problem.

Comment thread docs/architecture/theme-tokens.md Outdated
Comment on lines +171 to +174
value as before. Spacing has no base-unit derivation: `defineTheme` takes spacing only as
per-step token overrides, so nothing generates spacing values except the CLI's
theme templates, which copy a first-party theme's steps verbatim; a scaffolded
theme therefore emits `rem` steps once its source theme does. Theme authors keep

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docsite playground theme editor also generates spacing values: buildSpacingScale in apps/docsite/src/app/playground/themeEditor/helpers.ts writes every step as round(base × step)px, and the playground exports the result as defineTheme source. Either narrow this sentence to Core and the CLI or name that generator.

Comment thread docs/architecture/theme-tokens.md Outdated
| INV5 | Domain-token exports and theme-generation tests | Domain names disappear from validation or require importing unused domain implementation |
| INV6 | `packages/core/src/theme/tokens.test.ts` | JavaScript resolution disagrees with defaults, mode selection, references, or supported color expressions |
| INV8 | `defineTheme.test.ts`, template checks, and token-doc generation | A local name enters portable helpers/docs or can conflict with a portable declaration |
| INV9 | `tokens.test.ts` rem assertions, a real-Chromium root-font-size spec, and the theme-template check | A core spacing default in `px`, or a scaffolded theme emitting `px` steps |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This failure signal fires on what INV9 allows: a theme's documented px pin is an exception, and astryx theme eject scaffolds bundled copies of matcha and y2k that still emit px. Suggested: “… or a scaffolded theme emitting a px step its source theme does not document as an exception”, with evidence that reads the bundled themes; scripts/check-theme-template.test.mjs asserts nothing about spacing units.

…cribe helper values by unit, and stay in the present tense
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 12, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec a8e023d

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 12, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new spacing rule has the record owner's approval on the current commit, but two wording issues in architecture:theme-tokens should be fixed before it lands, and the fixing commit will need a fresh /approve-spec.

  • INV9 requires every spacing generator, including the CLI theme templates that copy first-party themes verbatim, to emit rem while also allowing a theme's documented px exception, and the verification row fails only a step “that no theme pinned”, so please state one rule in all three places, count the visual-gate probe generator in DEC-1, and link the record that owns the defineTheme input for DEC-1's premise.
  • The INV9 verification row cites the theme-template check, which reads only the annotated theme template and asserts nothing about spacing units, so please name checks that read the bundled theme copies and the playground's generated ramp.

[Automated review]

Comment thread docs/architecture/theme-tokens.md Outdated
Comment on lines +110 to +111
Anything that generates spacing steps — the CLI's theme templates and the
docsite playground's theme editor — emits `rem`. Non-CSS consumers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence has no exception, but lines 107–108 let a theme keep a documented px step, the CLI theme templates are byte copies of the first-party theme sources, and the INV9 row fails only a px step “that no theme pinned”. Please state one rule in all three places, for example: “a generated or copied spacing step is rem unless it reproduces a theme's documented px exception”.

Comment thread docs/architecture/theme-tokens.md Outdated
Comment on lines +174 to +178
`defineTheme` has no spacing base unit: it takes spacing only as per-step token
overrides. Two surfaces generate spacing steps and both emit `rem`: the CLI's
theme templates, which copy a first-party theme's steps verbatim, and the
docsite playground's theme editor, which derives a ramp from a base step and
exports it as `defineTheme` source. Theme authors keep control: a theme may pin

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two points here: the visual-gate probe generator also writes a spacing step (packages/themes/probe/src/probeConfig.ts is generated by .github/scripts/visual-gate/generate-probe-theme.mjs and sets '--spacing-4': '17px'), so “Two surfaces” undercounts; and the defineTheme premise is a fact this record says it does not own (line 119), so link architecture:theme-authoring-contract for it instead of restating it.

Comment thread docs/architecture/theme-tokens.md Outdated
| INV5 | Domain-token exports and theme-generation tests | Domain names disappear from validation or require importing unused domain implementation |
| INV6 | `packages/core/src/theme/tokens.test.ts` | JavaScript resolution disagrees with defaults, mode selection, references, or supported color expressions |
| INV8 | `defineTheme.test.ts`, template checks, and token-doc generation | A local name enters portable helpers/docs or can conflict with a portable declaration |
| INV9 | `tokens.test.ts` rem assertions, a real-Chromium root-font-size spec, and the theme-template check | A core spacing default in `px`, or a generator (CLI template, playground editor) emitting a `px` step that no theme pinned |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scripts/check-theme-template.test.mjs checks the annotated theme.template.ts (fields, token families and names, theming targets, doc topics, SYNC comments) and the Neutral palette files; it reads no bundled theme's spacing values and nothing from the playground editor, so it cannot detect the generator half of this failure signal. Please name evidence that reads the bundled theme copies' spacing values and the playground ramp instead.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Previews ready: Storybook and Sandbox were built with this PR's docsite. CI evidence will be added when available.

View Storybook for this PR · View Sandbox for this PR

…ce; the verification row names the checks that read units
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 12, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 4742aa5

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 12, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No remaining issues: INV9, DEC-1 and the INV9 verification row in architecture:theme-tokens now state one documented-exception rule for every spacing surface, DEC-1 links architecture:theme-authoring-contract for the defineTheme input, and the row names checks that read units for the core defaults, theme overrides, CLI copies and playground ramp. The record owner's approval is on this exact commit, so nothing more is needed here; the checks the row names arrive with the two implementation pull requests.

[Automated review]

@cixzhang
cixzhang merged commit c700d4c into main Oct 12, 2026
45 checks passed
@github-actions
github-actions Bot deleted the spec/spacing-tokens-rem branch October 13, 2026 06:27

This branch was successfully deployed

1 active deployment
Preview — 4742aa50 Deployed Oct 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant