fix(font): 修复 Astro Font API 组合字体变量的 CJK 回退#502
Merged
Leaf-0w0 merged 1 commit intoJul 13, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts the Astro Font API configuration so the generated --font-body and --font-cjk CSS variables contain only their respective font names (no embedded fallback chain), allowing the project’s composed --font-sans stack to correctly fall back from Latin to CJK fonts before reaching system fonts.
Changes:
- Set
fallbacks: []for--font-bodyand--font-cjkso they don’t inject generic/system fallbacks ahead of the next font in the composed stack. - Disable
optimizedFallbacksfor both fonts to avoid generating additional local optimized fallbacks that would interfere with ordering.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+58
to
+60
| // These variables are composed into --font-sans below. Keep their | ||
| // fallback lists empty; otherwise a system fallback after this Latin | ||
| // font prevents the following CJK font from ever being considered. |
Comment on lines
+77
to
+78
| // The final system fallback belongs to --font-sans, not this partial | ||
| // CJK font stack. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Astro Font API 为
--font-body和--font-cjk分别生成完整的 fallback 链。主题再通过下列配置组合它们:展开后,
--font-body自带的sans-serif会在--font-cjk之前生效。当英文字体缺少中文字符时,浏览器会直接回退到系统字体,而不会继续尝试 CJK 字体,导致“英文优先 ZenMaru、中文优先 Loli”的配置失效。解决方案
保留 Astro Font API 的字体加载、指纹化和预加载能力,但让两个待组合的 CSS 变量仅表示各自的字体:
fallbacks设为[];optimizedFallbacks设为false,避免生成度量优化后的本地 fallback;--font-sans统一提供。这样最终字体顺序变为:
验证
pnpm exec astro check:0 errors、0 warnings。--font-body与--font-cjk均只包含对应的 Astro 字体名。Related to #489