✒️ fix: Render Code in the Bundled Monospace Font (#16146)
Some checks are pending
Docker Dev Images Build / publish (push) Waiting to run
Sync Helm Chart Tags / Ignore non-main push (push) Waiting to run
Sync Helm Chart Tags / Sync chart tags (push) Waiting to run

`style.css` pinned every `code` and `pre` element to
`Consolas, Söhne Mono, Monaco, Andale Mono, Ubuntu Mono, monospace !important`.
The repository ships none of those faces, so Windows rendered code in Consolas
and macOS in Monaco, which carries neither an italic nor a bold face for the
browser to use. `!important` also outranked the 21 `pre` and `code` elements
that ask for `font-mono` by class, so the self-hosted Roboto Mono the app
already bundles was never used for code anywhere.

Move the stack to `theme.fontFamily.mono`, where `sans` already lives, so
Tailwind's preflight styles the bare elements and the `font-mono` utility
carries the same value. The tail is ordered so the glyphs the bundled latin
subset omits keep Roboto Mono's advance width.

Co-authored-by: Lia <lia@librechat.ai>
This commit is contained in:
lia-by-librechat[bot] 2026-09-20 21:00:35 -04:00 • committed by GitHub
parent ddd8d78d1d
commit 0cc52cd8c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 119 additions and 11 deletions

View file

@ -1225,16 +1225,10 @@ pre {
margin-top: 0;
}
code,
pre {
font-family:
Consolas,
Söhne Mono,
Monaco,
Andale Mono,
Ubuntu Mono,
monospace !important;
}
/* `code`, `kbd`, `samp` and `pre` take their font from Tailwind's preflight, which
reads `theme.fontFamily.mono` — see `tailwind.config.cjs`. Do not restate it here:
this file used to, with `!important`, which silently beat every `font-mono` class
in the app and pinned code to faces the repository does not ship. */
code.language-text,
code.language-txt,
code.language-plaintext,

93
client/src/style.spec.ts Normal file
View file

@ -0,0 +1,93 @@
import fs from 'node:fs';
import path from 'node:path';
import postcss, { AtRule, Rule } from 'postcss';
import type { ChildNode, Container, Result } from 'postcss';
/* eslint-disable @typescript-eslint/no-require-imports */
const tailwindcss = require('tailwindcss');
const tailwindConfig = require('../tailwind.config.cjs');
/* eslint-enable @typescript-eslint/no-require-imports */
type FontDeclaration = { selector: string; value: string; important: boolean };
const selectorOf = (parent: Container<ChildNode> | undefined): string => {
if (parent instanceof Rule) {
return parent.selector;
}
if (parent instanceof AtRule) {
return `@${parent.name} ${parent.params}`;
}
return '';
};
const collapse = (value: string): string => value.replace(/\s+/g, ' ').trim();
const firstFamily = (value: string): string =>
collapse(value.split(',')[0]).replace(/^['"]/, '').replace(/['"]$/, '');
/**
* The code font is one decision: `theme.fontFamily.mono` in `tailwind.config.cjs`, which
* Tailwind's preflight applies to `code`, `kbd`, `samp` and `pre`, and which the
* `font-mono` utility carries.
*
* `style.css` used to restate that decision with `!important`. Because `!important` beats
* specificity, one stylesheet rule outranked every `font-mono` class in the app and pinned
* code to `Consolas, Söhne Mono, Monaco, …` — faces this repository does not ship, so code
* rendered in Consolas on Windows and in Monaco on macOS, the latter carrying neither an
* italic nor a bold face for the browser to use, hence synthesized ones.
*/
describe('code typography', () => {
let fontFamilies: FontDeclaration[];
beforeAll(async () => {
const stylesheet = fs.readFileSync(path.join(__dirname, 'style.css'), 'utf8');
/** Raw content rather than the config's globs, so the emitted utilities depend on the
* names asserted here and not on the working directory a runner happens to use. */
const config = {
...tailwindConfig,
content: [{ raw: 'font-mono font-sans', extension: 'html' }],
};
const compiled: Result = await postcss([tailwindcss(config)]).process(stylesheet, {
from: undefined,
});
fontFamilies = [];
compiled.root.walkDecls('font-family', (declaration) => {
fontFamilies.push({
selector: collapse(selectorOf(declaration.parent)),
value: collapse(declaration.value),
important: declaration.important === true,
});
});
}, 60_000);
const utility = (): FontDeclaration | undefined =>
fontFamilies.find((entry) => entry.selector === '.font-mono');
it('declares no font-family that outranks a utility class', () => {
expect(fontFamilies.filter((entry) => entry.important)).toEqual([]);
});
it('gives every bare code element the same stack as the font-mono utility', () => {
const onCodeElements = fontFamilies.filter((entry) =>
entry.selector
.split(',')
.map((part) => part.trim())
.some((selector) => selector === 'code' || selector === 'pre'),
);
expect(utility()?.value).toBeTruthy();
expect(onCodeElements).not.toHaveLength(0);
for (const entry of onCodeElements) {
expect(entry.value).toBe(utility()?.value);
}
});
it('puts a self-hosted face first, so code renders the same on every platform', () => {
const hosted = fontFamilies
.filter((entry) => entry.selector.startsWith('@font-face'))
.map((entry) => firstFamily(entry.value));
expect(hosted).toContain(firstFamily(utility()?.value ?? ''));
});
});

View file

@ -17,7 +17,28 @@ module.exports = {
theme: {
fontFamily: {
sans: ['Inter', 'sans-serif'],
mono: ['Roboto Mono', 'monospace'],
/**
* Roboto Mono is self-hosted (the `@font-face` block in `style.css`), so code
* renders the same on every platform and carries real bold and italic faces
* rather than ones the browser synthesizes by smearing and shearing.
*
* The tail is reached while the font loads, if it fails, and per glyph for the
* characters the bundled latin subset omits — box drawing in terminal output
* most visibly. It is ordered so those glyphs come from a face whose advance
* width matches Roboto Mono's and keeps its columns: `ui-monospace` resolves
* to SF Mono on macOS, and Cascadia Mono ships with Windows Terminal.
* Consolas is last of the named faces because it is narrower than the rest.
*/
mono: [
'Roboto Mono',
'ui-monospace',
'SFMono-Regular',
'Menlo',
'Cascadia Mono',
'Liberation Mono',
'Consolas',
'monospace',
],
},
// fontFamily: {
// sans: ['Söhne', 'sans-serif'],