mirror of
https://github.com/run-llama/chat-ui.git
synced 2026-07-24 15:45:22 -04:00
[PR #142] [CLOSED] Fix: Prevents incorrect input commitment when selecting IME candidates #156
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/run-llama/chat-ui/pull/142
Author: @BaiRuic
Created: 6/20/2025
Status: ❌ Closed
Base:
main← Head:fix/ime-composition-race-condition📝 Commits (2)
cc8b061fix: resolve race condition during IME composition943fe14Create tricky-ravens-cheer.md📊 Changes
2 files changed (+8 additions, -1 deletions)
View changed files
➕
.changeset/tricky-ravens-cheer.md(+5 -0)📝
packages/chat-ui/src/chat/chat-input.tsx(+3 -1)📄 Description
This pull request addresses an issue where the Pinyin string is prematurely committed when a user selects a Chinese character candidate using a number key. (This PR is aimed to fix #135 )
The Problem
When using an IME (e.g., Chinese Pinyin) in the
ChatInputFieldcomponent, the following incorrect behavior occurs:The Root Cause
This issue stems from a subtle event ordering problem on certain platforms. When the number key is pressed to select a candidate, the
compositionendevent can fire before thekeydownevent.This causes our
isComposingstate to be set tofalseprematurely. Immediately after, when thehandleKeyDownfunction processes the number key'skeydownevent, it seesisComposingasfalseand may incorrectly handle the key press, causing the then-current value (the Pinyin) to be treated as final. The IME's replacement of Pinyin with the actual characters happens after this, but by then it's too late.The Solution
To resolve this, this PR introduces a
setTimeoutto theonCompositionEndevent handler.By delaying the execution of
setIsComposing(false), we ensure that theisComposingflag remainstrueuntil after thekeydownevent has been fully processed. This allowshandleKeyDownto correctly ignore the key event, giving the IME the necessary time to complete its composition and correctly update the input field with the selected characters.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.