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 d58df45

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 per stroke. The RestoreDOM component was restoring childList mutations during composition, which interrupted the IME session and caused the first stroke to be committed prematurely (e.g., writing '我' would produce '一我'). The fix skips all DOM restoration during composition in RestoreDOM. This preserves the user's input state while allowing Slate state updates and onChange to fire normally.
1 parent addf0c5 commit d58df45

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
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 per stroke. The RestoreDOM component was restoring childList mutations during composition, which interrupted the IME session and caused premature commits.
8+
9+
**Fix:** Skip all DOM restoration during composition in RestoreDOM. This preserves the user's input state while allowing Slate state updates and onChange to fire normally.
10+

packages/slate-react/src/components/restore-dom/restore-dom-manager.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RefObject } from 'react'
22
import { ReactEditor } from '../../plugin/react-editor'
3-
import { isTrackedMutation } from 'slate-dom'
3+
import { isTrackedMutation, IS_COMPOSING } from 'slate-dom'
44

55
export type RestoreDOMManager = {
66
registerMutations: (mutations: MutationRecord[]) => void
@@ -32,6 +32,15 @@ export const createRestoreDomManager = (
3232

3333
function restoreDOM() {
3434
if (bufferedMutations.length > 0) {
35+
// FIX: Skip all DOM restoration during composition to prevent interrupting
36+
// the IME session. This fixes Android handwriting input issue where
37+
// restoring childList mutations would cause premature stroke commits.
38+
// See: https://github.com/ianstormtaylor/slate/issues/5979
39+
if (IS_COMPOSING.get(editor)) {
40+
clear()
41+
return
42+
}
43+
3544
bufferedMutations.reverse().forEach(mutation => {
3645
if (mutation.type === 'characterData') {
3746
// We don't want to restore the DOM for characterData mutations

0 commit comments

Comments
 (0)