From 0cc52cd8c71e8ccbceb8f001ddf8059b10501fce Mon Sep 17 00:00:00 2001 From: "lia-by-librechat[bot]" <328778573+lia-by-librechat[bot]@users.noreply.github.com> Date: Sun, 20 Sep 2026 21:00:35 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=92=EF=B8=8F=20fix:=20Render=20Code=20in?= =?UTF-8?q?=20the=20Bundled=20Monospace=20Font=20(#16146)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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 --- client/src/style.css | 14 ++---- client/src/style.spec.ts | 93 ++++++++++++++++++++++++++++++++++++++ client/tailwind.config.cjs | 23 +++++++++- 3 files changed, 119 insertions(+), 11 deletions(-) create mode 100644 client/src/style.spec.ts diff --git a/client/src/style.css b/client/src/style.css index 5dea3d61d0..1e76b977e7 100644 --- a/client/src/style.css +++ b/client/src/style.css @@ -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, diff --git a/client/src/style.spec.ts b/client/src/style.spec.ts new file mode 100644 index 0000000000..b8f88a27c4 --- /dev/null +++ b/client/src/style.spec.ts @@ -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 | 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 ?? '')); + }); +}); diff --git a/client/tailwind.config.cjs b/client/tailwind.config.cjs index 9c3d23cac1..2437e8d8cd 100644 --- a/client/tailwind.config.cjs +++ b/client/tailwind.config.cjs @@ -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'],