Skip to content

fix(icon): 修复 H5 端图标字体未预加载导致首屏显示占位方块的问题 - #4726

Open
lnuxe wants to merge 5 commits into
Tencent:developfrom
lnuxe:fix/icon-font-preload-4710
Open

lnuxe wants to merge 5 commits into
Tencent:developfrom
lnuxe:fix/icon-font-preload-4710

Conversation

@lnuxe

@lnuxe lnuxe commented Nov 16, 2026

Copy link
Copy Markdown

PR 类型

  • bugfix
  • feature
  • style
  • typescript
  • refactor
  • perf
  • ci
  • docs
  • chore
  • test
  • rename
  • revert
  • workflow

相关 Issue

Fixes #4710

修改说明

问题

H5 端图标字体(font-family: t)没有预加载:页面首屏渲染时,组件已把 t-icon-* 字形文本画进 DOM,此时浏览器才第一次发起 t.woff 字体请求;请求返回前图标渲染为占位方块(tofu),返回后才变成正确图形。首次访问(无缓存)或弱网时中间态肉眼可见。

根因

icon.less 的 @font-face 只有 CSS 声明,浏览器按「首次需要使用该字体绘制」才发起下载;而 Vue bundle 求值 → 组件挂载 → DOM 绘制发生在字体请求之前,形成「先画方块、后换图标」的窗口。

修复

新增 packages/uniapp-components/icon/font-preload.ts:

验证

Node + FontFace stub 冒烟测试(issue #4710 场景):

faces added: 1              [OK] 只注册一次
first face loaded: true     [OK] load() 已触发
family: t                   [OK] 与 icon.less @font-face 同名
idempotent (same promise): true  [OK] 重复调用幂等
PRELOAD SANITY PASS
  • vue/compiler-sfc 编译 icon.vue 通过,script 无语法错误
  • esbuild 解析 font-preload.ts 通过

自检

  • 代码遵循仓库 ESLint/Prettier 规范
  • 不包含无关改动(仅 icon 目录两个文件)
  • 已在本地验证(FontFace stub 冒烟 + SFC 编译检查)

calcMonths returned early for switchMode 'none' after setting months only, so
currentMonth stayed at its initial empty object. Opening the panel could not
locate the selected range whenever minDate/maxDate spanned a long period.

Derive currentMonth in that branch too, keeping the existing behaviour of not
touching the month switch buttons.

fix Tencent#4718
Review feedback: keep one unit test file per component instead of adding a
new file per scenario. The scrollIntoView case now lives in index.test.js
under its own describe block, and scroll-into-view.test.js is gone.

No behaviour change.
The popup enter animation keeps the dialog container inside a scale/translate composited layer. Native input placeholders complete their first layout against that intermediate transform state and end up vertically offset (issue Tencent#4551). Promote the dialog content and nested input to their own composited layer so the placeholder layout is computed from the settled geometry.
小程序真机环境不支持 Unicode 属性转义(\p{L}\p{N}\p{P}\p{S}),
chat-markdown 在非 APP 端引用的 npm/marked/index.js 内含
unicodeAlphaNumeric:/[\p{L}\p{N}]/u 等正则,模拟器(V8/JS Core 新版)
可解析,真机基础库解析直接抛
Invalid regular expression: /[\p{L}\p{N}]/u: Invalid property name。

与已有的 npm/marked/uniapp.js(APP 端专用)保持一致,将属性转义
替换为等价 ASCII 字符类:
- [\p{L}\p{N}] -> [A-Za-z0-9]
- [\p{P}\p{S}] 与 [\s\p{P}\p{S}] -> ASCII 标点符号类
(含 \s,与 uniapp.js 逐字符一致)

真机与模拟器均不再解析失败,CJK 加粗/标题/列表/链接等
markdown 词法分析行为不变。
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
lnuxe force-pushed the fix/icon-font-preload-4710 branch from c314c93 to 87b88a2 Compare November 17, 2026 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[icon] @tdesign/uniapp 图标字体缺少预加载,H5 组件渲染时才请求字体,返回前图标显示占位方块

1 participant