Skip to content

feat(theme): remove runtime font loading from defineTheme - #2226

Merged
cixzhang merged 1 commit into
mainfrom
navi/feat/remove-font-loading
May 19, 2026
Merged

cixzhang merged 1 commit into
mainfrom
navi/feat/remove-font-loading

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

What

Removes the runtime font loading mechanism from defineTheme. Consumers should load fonts themselves (e.g. <link> tag in <head> or @import in CSS).

Why

The typography.url + useThemeFontLoading approach was:

  • Unreliable (CSP restrictions, SSR environments, timing/FOUT issues)
  • Already positioned as a "fallback" that logged console warnings encouraging the manual approach
  • Only used by the Stone theme

What's removed

  • ThemeFontSource type and fonts field from XDSDefinedTheme
  • url field from TypographyRole
  • useThemeFontLoading hook from XDSTheme
  • Font derivation/merging logic in defineTheme()
  • url declarations from Stone theme

What still works

typography.family and typography.fallbacks are unchanged — defineTheme still sets --font-family-body, --font-family-heading, --font-family-code tokens so the font is applied once loaded.

Migration

If you were relying on the runtime font injection, add a <link> to your HTML:

<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700&display=swap" />

Font loading via the typography.url field and useThemeFontLoading hook
was unreliable (CSP, SSR, timing issues) and only used by the Stone
theme. Consumers should import fonts themselves via <link> tags or
@import in their CSS.

Removes:
- ThemeFontSource type and fonts field from XDSDefinedTheme
- url field from TypographyRole
- useThemeFontLoading hook from XDSTheme
- Font derivation/merging logic in defineTheme()
- url declarations from Stone theme

typography.family and typography.fallbacks still work — defineTheme
sets the --font-family-* tokens so the font is used once loaded.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 19, 2026
@vercel

vercel Bot commented May 19, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
xds-sandbox Ready Ready Preview, Comment May 19, 2026 6:43pm

Request Review

@github-actions

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

Package Size (ESM) Size (CJS) Gzipped
@xds/core 19.1KB 29.5KB 4.4KB

Accessibility Audit

Status: No accessibility violations detected.


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

@cixzhang
cixzhang enabled auto-merge (squash) May 19, 2026 23:55
@cixzhang
cixzhang merged commit 2458285 into main May 19, 2026
20 checks passed
cixzhang added a commit that referenced this pull request Jun 21, 2026
Font loading via the typography.url field and useThemeFontLoading hook
was unreliable (CSP, SSR, timing issues) and only used by the Stone
theme. Consumers should import fonts themselves via <link> tags or
@import in their CSS.

Removes:
- ThemeFontSource type and fonts field from XDSDefinedTheme
- url field from TypographyRole
- useThemeFontLoading hook from XDSTheme
- Font derivation/merging logic in defineTheme()
- url declarations from Stone theme

typography.family and typography.fallbacks still work — defineTheme
sets the --font-family-* tokens so the font is used once loaded.
cixzhang added a commit that referenced this pull request Jun 21, 2026
Font loading via the typography.url field and useThemeFontLoading hook
was unreliable (CSP, SSR, timing issues) and only used by the Stone
theme. Consumers should import fonts themselves via <link> tags or
@import in their CSS.

Removes:
- ThemeFontSource type and fonts field from XDSDefinedTheme
- url field from TypographyRole
- useThemeFontLoading hook from XDSTheme
- Font derivation/merging logic in defineTheme()
- url declarations from Stone theme

typography.family and typography.fallbacks still work — defineTheme
sets the --font-family-* tokens so the font is used once loaded.
@cixzhang
cixzhang deleted the navi/feat/remove-font-loading branch June 21, 2026 16:59
cixzhang pushed a commit that referenced this pull request Aug 15, 2026
* feat(cli): warn when a theme names fonts it does not load

`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 (#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 #5015

* test(cli): cover font-warning edge cases; fix multi-line quoted names

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.

This branch was successfully deployed

1 active deployment
Preview — c5e6d714 Deployed May 19, 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