Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

✒️ fix: Render Code in the Bundled Monospace Font (#16146)

lia-by-librechat[bot]0cc52cd8c71e
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<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 ?? ''));
+ });
+});
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'],