Skip to content

fix(input): 修复 Mac 端韩语等 IME 组合输入时内容闪烁的问题 - #4727

Open
lnuxe wants to merge 6 commits into
Tencent:developfrom
lnuxe:fix/input-ime-flicker-4606
Open

lnuxe wants to merge 6 commits into
Tencent:developfrom
lnuxe:fix/input-ime-flicker-4606

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 #4606

修改说明

问题

Mac 端输入韩语时,t-input / t-textarea 内容闪烁(见 issue 内录屏)。input、textarea 均存在;原生 input 组件没有此问题。

根因

组件的 onInput 把每次 input 事件的值通过 setData({ value }) 回写,而 wxml 中 <input value="{{value}}"> 又绑定该值——形成「原生输入 → setData 回写 → 原生重新应用 value」的回环。

韩语等 IME 组合输入时,每个 keystroke 的中间态都触发一次回写;原生控件在组合会话进行中被重新应用 value 会重置 IME 组合态,导致文字反复消失/重绘,即肉眼可见的闪烁。原生 input 不回写,因此无此问题。

修复

核心原则:原生控件本就显示用户正在输入的中间态,无需回写确认。

场景 旧行为 新行为
输入(不截断) setData({value}) 回写 → 打断 IME 只按限长规则同步 count,不回写 value;change 事件携带原始值
输入(超限截断) 回写截断值 保持回写(受控纠偏必须干预)
相同值 setData 仍写 value 短路:只同步 count
外部(父组件)更新 value 属性 无 observer 新增 observer 同步到内部展示(内部输入不经过 observer,避免互相打断)

input 新增 calculateCount(与截断分支同一套 maxcharacter/maxlength 计数语义);textarea 直接复用既有 calculateValue。

验证

新增回归测试 packages/components/input/__test__/ime-composition.test.js:
  ✓ 韩语组合输入过程中 change 事件携带最新中间态(ㄱ→가→각 序列)
  ✓ 外部更新 value 属性同步到内部展示

组件套件回归:
Test Suites: 7 passed, 7 total    (input/textarea/ime 相关)
Tests:       51 passed, 51 total

既有 maxcharacter 受控截断用例(CJK 计数 9 等)全部保持通过。

自检

  • 代码遵循仓库 ESLint/Prettier 规范
  • 不包含无关改动
  • 已在本地验证(新增 2 例回归 + 既有 51 例套件全通过)

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 求值阶段,早于首屏组件渲染。
input/textarea 的 onInput 此前把每次 input 事件的中间态通过
setData({value}) 回写给原生控件;Mac 端韩语等 IME 组合输入时,
回写会打断输入法组合态(composition 被重置),造成内容反复
闪烁(issue Tencent#4606)。原生 input 组件无此问题,因为从不回写。

修复原则:输入过程中原生控件本就显示用户输入的中间态,
仅在限长(maxcharacter/maxlength)会截断内容时才回写做受控
纠偏;其余情况只按限长规则同步计数并抛出 change(携带原始值)。

- onInput 非截断分支不再 setData value(消除组合态打断源)
- 新增 calculateCount(input)/复用 calculateValue(textarea)
  保证计数语义与截断分支一致
- updateValue 相同值短路:只同步计数不回写
- 新增 value 属性 observer:外部(父组件)受控更新仍同步到
  内部展示,内部输入值不经过 observer,避免互相打断
- 新增 ime-composition.test.js 回归测试(2 例)
@lnuxe
lnuxe force-pushed the fix/input-ime-flicker-4606 branch from f85d6a5 to 1018010 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.

[Input] Mac输入韩语时内容闪烁

1 participant