WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 068ee68

Browse files
author
zenggenfa
committed
fix(slate-react): prevent premature flush during composition for Android handwriting input
Fixes #5979 On Android devices, handwriting input triggers compositionStart/compositionEnd events per stroke. The flush() function was being called during composition, causing DOM changes that interrupt the composition session. This resulted in the first stroke being committed prematurely (e.g., writing '我' would produce '一我'). The fix adds IS_COMPOSING checks in flush(), scheduleAction(), and handleInput() to prevent flushing during composition. The pending diffs are now properly accumulated and flushed only after compositionEnd.
1 parent addf0c5 commit 068ee68

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

.changeset/brave-dragons-write.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'slate-react': patch
3+
---
4+
5+
Fix Android handwriting input where first stroke commits prematurely (e.g., '我' becomes '一我').
6+
7+
**Cause:** Android handwriting triggers compositionStart/compositionEnd per stroke. The flush() was being called during composition, causing DOM changes that interrupted the session.
8+
9+
**Fix:** Added IS_COMPOSING check at the start of flush() to skip flushing during composition. Pending changes are now properly accumulated and flushed after compositionEnd.
10+

packages/slate-react/src/hooks/android-input-manager/android-input-manager.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ export function createAndroidInputManager({
124124
}
125125

126126
const flush = () => {
127+
// FIX: Don't flush during composition to prevent DOM changes that interrupt
128+
// the composition session. This fixes Android handwriting input issue.
129+
// See: https://github.com/ianstormtaylor/slate/issues/5979
130+
if (IS_COMPOSING.get(editor)) {
131+
return
132+
}
133+
127134
if (flushTimeoutId) {
128135
clearTimeout(flushTimeoutId)
129136
flushTimeoutId = null

0 commit comments

Comments
 (0)