Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix: apply theme body font to the theme scope root (#6450)

Kenton Quatmanff6777ad235a
diff --git a/.changeset/theme-scope-root-base-font.md b/.changeset/theme-scope-root-base-font.md
new file mode 100644
index 0000000000..867ce8d999
--- /dev/null
+++ b/.changeset/theme-scope-root-base-font.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Apply the theme's body font to the theme scope root. Generated theme CSS set `font-family` on headings, paragraphs, and code elements but never established a base font on the page, so components styled with `font-family: inherit` (SideNav items, Buttons) fell back to the browser default serif. The generator now emits `font-family: var(--font-family-body)` on `:scope`, which inherits through the tree.
+
+@kentonquatman
diff --git a/packages/core/src/theme/generateThemeRules.test.ts b/packages/core/src/theme/generateThemeRules.test.ts
index 72eb45b5c3..14a1dab9e5 100644
--- a/packages/core/src/theme/generateThemeRules.test.ts
+++ b/packages/core/src/theme/generateThemeRules.test.ts
@@ -276,6 +276,36 @@ describe('generateThemeRules', () => {
expect(rules.some(r => r.includes(':where(hr)'))).toBe(true);
});
+ it('applies the theme body font to the scope root', () => {
+ // Components styled with `font-family: inherit` (SideNav items, Buttons)
+ // resolve against this; without it they fall back to the browser default
+ // serif since nothing else sets a page font.
+ const fontTheme = defineTheme({
+ name: 'with-body-font',
+ typography: {body: {family: 'Figtree', fallbacks: 'sans-serif'}},
+ tokens: {},
+ components: {},
+ });
+ const fontRules = generateThemeRules(fontTheme);
+ const fontRule = fontRules.find(
+ r =>
+ r.includes(':scope') &&
+ r.includes('font-family: var(--font-family-body)'),
+ );
+ expect(fontRule).toBeDefined();
+ expect(fontRule).toBe(' :scope {\n font-family: var(--font-family-body);\n }');
+ });
+
+ it('emits no scope font rule when the theme declares no body font', () => {
+ // A bare theme contributes no scope rules of its own.
+ const fontRule = rules.find(
+ r =>
+ r.includes(':scope') &&
+ r.includes('font-family: var(--font-family-body)'),
+ );
+ expect(fontRule).toBeUndefined();
+ });
+
// --- Prop-level color overrides ---
it('includes color prop overrides for text and heading', () => {
diff --git a/packages/core/src/theme/generateThemeRules.ts b/packages/core/src/theme/generateThemeRules.ts
index 2af3a0fb69..98b63c37ba 100644
--- a/packages/core/src/theme/generateThemeRules.ts
+++ b/packages/core/src/theme/generateThemeRules.ts
@@ -414,6 +414,16 @@ export function generateThemeRules(theme: ThemeRuleSource): string[] {
parts.push(` :scope {\n${declarations}\n }`);
}
+ // 1b. Base font — apply the theme's declared body font to the scope root.
+ // Components styled with `font-family: inherit` (SideNav items, Buttons)
+ // otherwise resolve against the browser default serif, since nothing else
+ // sets a page font. `font-family` inherits, so one rule on :scope covers
+ // the tree. Only emitted when the theme declares a body font, so a bare
+ // theme still contributes no scope rules of its own.
+ if (tokens['--font-family-body']) {
+ parts.push(` :scope {\n font-family: var(--font-family-body);\n }`);
+ }
+
// 2. Component overrides: stable .astryx-* target classes combined with
// reflected data-* selectors for visual props and runtime states.
if (theme.components) {