Repository navigation
Conversation
lnuxe
requested review from
anlyyao,
betavs,
jarmywang,
jin0209,
novlan1 and
zydemail
as code owners
November 16, 2026 09:06
lnuxe
force-pushed
the
fix/icon-font-preload-4710
branch
from
November 17, 2026 02:04
c314c93 to
87b88a2
Compare
H5 端图标字体(font-family: t)此前没有预加载:首个 t-icon-* 渲染进 DOM 后浏览器才发起 t.woff 请求,请求返回前图标显示为 占位方块(tofu),首次访问或弱网时中间态肉眼可见(issue Tencent#4710)。 新增 font-preload.ts:模块加载阶段通过 FontFace API 主动触发 字体加载,与 icon.less 的 @font-face 指向同一 URL,浏览器复用 同一请求不重复下载;幂等(缓存 Promise),失败静默回退到原有 CSS 触发路径。小程序/APP 端无 document.fonts,直接跳过。 icon.vue 引入该模块并在顶层调用 ensureIconFontLoaded(), 使字体请求提前到 bundle 求值阶段,早于首屏组件渲染。
lnuxe
force-pushed
the
fix/icon-font-preload-4710
branch
from
November 23, 2026 08:00
87b88a2 to
0b9b0ab
Compare
Author
|
分支已重建,说明一下改动: 之前这个分支是续在 现在已从
改动文件只有 另外 PR 描述之前用的是自己写的小标题,把仓库模板里的「📝 更新日志」段整个删掉了,已按 |
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.
🤔 这个 PR 的性质是?
🔗 相关 Issue
Fixes #4710
💡 需求背景和解决方案
问题
H5 端图标字体(
font-family: t)没有预加载:页面首屏渲染时,组件已把t-icon-*字形文本画进 DOM,浏览器此时才第一次发起t.woff请求;请求返回前图标渲染为占位方块(tofu),返回后才变成正确图形。首次访问(无缓存)或弱网时中间态肉眼可见。根因
icon.less的@font-face只有 CSS 声明,浏览器按「首次需要用该字体绘制」才发起下载;而 bundle 求值 → 组件挂载 → DOM 绘制发生在字体请求之前,形成「先画方块、后换图标」的窗口。修复
新增
packages/uniapp-components/icon/font-preload.ts:icon.vue模块加载(bundle 求值)阶段即通过 FontFace API 主动触发字体加载,把请求提前到首屏渲染之前;icon.less的@font-face指向同一 URL(https://tdesign.gtimg.com/icon/0.4.6/fonts/t.woff),浏览器复用同一请求,不会重复下载;@font-face触发路径,不改变任何既有行为;document.fonts,canUseFontFace检测直接跳过,零开销。验证
Node + FontFace stub 冒烟(issue #4710 场景):
另:
vue/compiler-sfc编译icon.vue通过,esbuild解析font-preload.ts通过。📝 更新日志
tdesign-miniprogram