Skip to content

feat(cli): warn when a theme names fonts it does not load - #5045

Merged
cixzhang merged 2 commits into
meta:mainfrom
AKnassa:rocky/issue-5015-theme-font-warning
Aug 15, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
AKnassa:rocky/issue-5015-theme-font-warning

Conversation

@AKnassa

@AKnassa AKnassa commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #5015

Heads up @cixzhang: saw you self-assigned this shortly after filing, so this may cross work you already have in flight. No hard feelings at all if you'd rather land your own version; happy to close this one or rebase onto yours. Sharing since it was ready.

What this does

astryx theme build now tells a theme author when their theme names a font that nothing actually loads, and prints the exact <link> and @font-face snippet to add. The docs also gain the loading recipe the disclaimers always pointed at.

Why

A theme can name any webfont, the build succeeds, the CSS is correct, and the browser quietly falls back on every clean machine. Nothing in the pipeline said so. This covers parts (1) and (2) of the issue; part (3), the url field question, is a design call and is left untouched here.

What changed

  • New check in theme build: resolved --font-family-* tokens and component-level fontFamily values are compared against CSS generics and known preinstalled system families (including the shipped themes' deliberate fallback stacks, so none of the seven themes false-warns). Anything unrecognized is treated as a webfont.
  • One warning per font goes to the receipt (--json sees it) and stderr; the copy-pasteable fix prints after the install instructions, in the slot that held the dead resolvedTheme.fonts block from before feat(theme): remove runtime font loading from defineTheme #2226.
  • astryx docs typography gains a "Loading Custom Fonts" section (Google Fonts and self-hosted recipes, font-display: swap, real fallback stacks); the theme docs' production-build section points at it.
  • 22 new tests across unit, API, and CLI layers; changeset included.

Expected side effect: repo builds of the shipped webfont themes (neutral, butter, chocolate, gothic, matcha, stone, y2k) now print this warning by design, the same way those builds already print install instructions for them.

How to see it

Build any theme that names a webfont:

$ astryx theme build ./demo.ts
...
⚠ Theme "demo" names fonts it does not load: "Space Grotesk", "Fraunces", "JetBrains Mono"
  The built CSS only sets font-family — load these in your app, or every
  browser quietly falls back.

  Google Fonts (add :wght@… axes as your theme's weights require):

    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Space+Grotesk&family=Fraunces&family=JetBrains+Mono&display=swap" />

  Self-hosted (repeat per family and weight):

    @font-face {
      font-family: "Space Grotesk";
      src: url('/fonts/space-grotesk.woff2') format('woff2');
      font-display: swap;
    }

  Recipe and fallback-stack guidance: astryx docs typography

A theme that only names system fonts prints nothing new. astryx docs typography shows the new "Loading Custom Fonts" section.

Round 2: edge-case tests

Nine new tests: null and non-string resolved-theme inputs, fontFamily nested under pseudo-class override blocks (unit and through the real defineTheme path), var() fallbacks containing another var(), case-variant generic keywords, multi-line quoted family names, css2 URL percent-encoding, and the --json envelope contract (warnings in the receipt, snippet suppressed, stdout stays parseable).

The multi-line test caught a real tokenizer bug: the quoted-name check lacked dotAll, so a family quoted across lines kept its quote characters, breaking dedupe, system-font matching, and the css2 URL. Fixed with the /s flag.

`astryx theme build` now checks the resolved --font-family-* tokens and
component-override fontFamily values against CSS generics and known
preinstalled system families (including the shipped themes' deliberate
fallback stacks, so none of the seven themes false-warns). Anything else
gets one warning per family in the receipt and on stderr, plus the
<link>/@font-face snippet printed after the install instructions — the
slot that previously held a dead resolvedTheme.fonts block (meta#2226
removed the field it read).

`astryx docs typography` gains a Loading Custom Fonts section (Google
Fonts and self-hosted recipes, font-display: swap, real fallback
stacks); the theme docs' production-build section points at it.

Shipped webfont themes now warn by design in repo builds — the same
builds already print install instructions for them.

Part (3) of the issue (the phantom url field in the docs) is a design
call and is left untouched.

Closes meta#5015
@vercel

vercel Bot commented Aug 15, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 15, 2026 2:12am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 15, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Aug 15, 2026
@github-actions

github-actions Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 15, 2026
Nine tests: null/non-string resolved-theme inputs, fontFamily nested
under pseudo-class override blocks (unit and through the defineTheme
path), var() fallbacks containing another var(), case-variant generic
keywords, css2 URL percent-encoding, and the --json envelope contract
(warnings in the receipt, snippet suppressed, stdout stays parseable).

The multi-line test caught a real bug: the quoted-name check lacked
dotAll, so a family quoted across lines (template-literal theme
sources) kept its quote characters, breaking dedupe, system-font
matching, and the css2 URL. Fixed with the /s flag.
github-actions Bot added a commit that referenced this pull request Aug 15, 2026
@AKnassa
AKnassa marked this pull request as ready for review August 15, 2026 03:06

@cixzhang cixzhang 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.

Oh thank you for getting this!

@cixzhang
cixzhang enabled auto-merge (squash) August 15, 2026 23:47
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Aug 15, 2026
@cixzhang
cixzhang merged commit 3afdd73 into meta:main Aug 15, 2026
24 checks passed
@github-actions
github-actions Bot deleted the rocky/issue-5015-theme-font-warning branch August 16, 2026 06:35

This branch was successfully deployed

1 active deployment
Preview — eedd5504 Deployed Aug 15, 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. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nothing helps a theme author load the font they just named

2 participants