fix: render CJK glyphs in terminal (fontFamily + optional WebGL renderer)#823
fix: render CJK glyphs in terminal (fontFamily + optional WebGL renderer)#823mhit wants to merge 1 commit into
Conversation
CJK characters (Japanese/Chinese/Korean) frequently rendered as black
boxes ("tofu") in the xterm.js terminal. Two compounding causes:
1. TERMINAL_OPTIONS.fontFamily had no CJK font, so CJK could only come
from the generic `monospace` fallback, which the WebGL/Canvas glyph
atlas rasterizes poorly (missing-glyph boxes).
2. The WebGL renderer was loaded unconditionally and handles fallback
glyphs worse than the DOM renderer.
Changes:
- Add cross-platform CJK monospace fallbacks to fontFamily so the atlas
has an explicit CJK font to rasterize from.
- Add isWebglDisabled() so the WebGL addon can be skipped (DOM renderer)
via localStorage 'terminal-disable-webgl' or VITE_TERMINAL_DISABLE_WEBGL,
which renders CJK reliably even with an imperfect font stack.
Fixes siteboon#822
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR fixes CJK character rendering in the built-in terminal by expanding the font family to include cross-platform CJK monospace fonts and introducing a WebGL renderer toggle. Users can disable the WebGL renderer via localStorage or environment variable to improve CJK glyph atlas rendering reliability. ChangesTerminal CJK rendering and WebGL configuration
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Summary
CJK characters (Japanese / Chinese / Korean) are frequently rendered as solid black boxes ("tofu") in the built-in xterm.js terminal, while the same text renders fine elsewhere in the app. This fixes the two compounding root causes.
Root cause
fontFamilyhas no CJK font (src/components/shell/constants/constants.ts).Menlo, Monaco, "Courier New", monospacehas no CJK coverage, so CJK can only come from the genericmonospacefallback.src/components/shell/hooks/useShellTerminal.ts). The xterm.js WebGL/Canvas renderer rasterizes glyphs into a texture atlas and handles fallback glyphs poorly, so CJK obtained via genericmonospacefrequently comes out as the missing-glyph box. The intermittent, per-glyph nature of the breakage is the signature of this atlas/fallback issue (a real OS coverage gap would drop all CJK).Changes
TERMINAL_OPTIONS.fontFamily, giving the glyph atlas an explicit CJK font to rasterize from.isWebglDisabled()and gate theWebglAddonbehind it, so the WebGL renderer can be turned off (falling back to the DOM renderer, which renders CJK reliably). Resolution order:localStorage['terminal-disable-webgl'] === 'true'(runtime, no rebuild)VITE_TERMINAL_DISABLE_WEBGL === 'true'(build-time default)How to test
echo 日本語テスト 中文 한국어.localStorage.setItem('terminal-disable-webgl','true')in DevTools and reopen the terminal — the DOM renderer renders CJK reliably even with an imperfect font stack.Notes / trade-offs
Fixes #822
🤖 Generated with Claude Code
Summary by CodeRabbit