fix(desktop): prevent .xterm from inheriting Tailwind's sans-serif stack (#3570)#3758
fix(desktop): prevent .xterm from inheriting Tailwind's sans-serif stack (#3570)#3758allenxln wants to merge 1 commit intosuperset-sh:mainfrom
Conversation
…inheritance (superset-sh#3570) xterm.css does not declare font-family on .xterm itself (only on .xterm-accessibility-tree), so the element inherits from body, which picks up Tailwind preflight's default sans-serif stack. That disagrees with terminal.options.fontFamily (a monospace stack from appearance/ index.ts), and the mismatch can corrupt the WebGL glyph atlas on startup in CJK locales.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Gentle nudge — happy to keep waiting, but wanted to leave one breadcrumb in case it helps prioritize: #3554 (fix(desktop): recover terminal from non-monospace font crash) addressed the case where the xterm runtime ends up with a proportional font. This PR is arguably a closely related "silent" variant of the same class: the No rush on merging; just flagging the connection in case it shortens the review context. Still happy to follow up with a broader fix (propagating |
What this does
Adds a
font-family: ui-monospace, monospacedeclaration to the existing.xtermrule inapps/desktop/src/renderer/globals.css, so the terminal element's computedfont-familystops inheriting Tailwind preflight's sans-serif stack.Why
While investigating #3570 (corrupted glyphs in CJK locales on macOS),
getComputedStyle(document.querySelector('.xterm')).fontFamilyreturned:— no monospace family at all. Meanwhile
terminal.options.fontFamily(set interminal-runtime.ts:109fromappearance/index.ts:42) is a monospace stack starting with JetBrains Mono.Tracing the CSS:
@xterm/xterm@6.0.0/css/xterm.cssnever setsfont-familyon.xtermitself (only on.xterm-accessibility-tree), by design — xterm expects the renderer'soptions.fontFamilyto drive glyph rendering..xtermrule inapps/desktop/src/renderer/globals.cssonly setsheight/width..xterminherits frombody, which uses Tailwind v4 preflight's defaultui-sans-serif, system-ui, sans-serif, ...stack.When xterm's internal CSS-based measurement paths (DOM measure fallback, ligatures addon shaping via
getComputedStyle) run against that proportional stack while the WebGL renderer rasterizes glyphs from the monospace stack, the texture atlas gets written with metrics that don't match the cell grid — the exact "distorted, overlapping glyph fragments" shown in the issue.Two reported workarounds (DevTools open, window resize) both trigger xterm
resize→ atlas rebuild at a point when the initial font-loading / CSS race has settled, which is consistent with this hypothesis.Scope
Intentionally minimal (single declaration). A more complete fix would make
.xterm's DOMfont-familytrackterminal.options.fontFamilyexactly (e.g. by injecting the stack as a CSS variable fromterminal-runtime.ts), so a user-customized terminal font is also reflected in the DOM. Happy to follow up with that once the direction is confirmed.Related
Testing
I haven't set up a local desktop build to validate end-to-end, and I'm keeping this as Draft partly for that reason. A few honest notes on why I think that's an acceptable state for this particular change:
@layer baserule — very small blast radius, and straightforward to review or revert.That said, happy to do whatever local setup is expected — just flag it. Reviewers with a running build and a CJK-locale macOS should be able to verify by:
.xterm's computedfont-familybefore and after this change.Summary by cubic
Add
font-family: ui-monospace, monospaceto the.xtermrule so the terminal stops inheriting Tailwind’s sans-serif stack. This prevents WebGL atlas corruption and garbled glyphs on startup (notably in CJK locales on macOS) and fixes #3570.Written for commit 4692449. Summary will update on new commits.