Skip to content

Commit

Permalink
fix ime double input with mark (ianstormtaylor#4158)
Browse files Browse the repository at this point in the history
* fix ime double when apply mark

* add changeset

* refactor to use auto-incrementing key and add comments for it

* Update lovely-walls-knock.md

* Update lovely-walls-knock.md

Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
  • Loading branch information
2 people authored and beorn committed Apr 13, 2021
1 parent 6ce60e1 commit 6346527
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lovely-walls-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Fixed a bug that resulted in doubly-input characters when using an IME.
11 changes: 10 additions & 1 deletion packages/slate-react/src/components/leaf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import String from './string'
import { PLACEHOLDER_SYMBOL } from '../utils/weak-maps'
import { RenderLeafProps } from './editable'

// auto-incrementing key for String component, force it refresh to
// prevent inconsistent rendering by React with IME input
let keyForString = 0
/**
* Individual leaves in a text node with unique formatting.
*/
Expand Down Expand Up @@ -43,7 +46,13 @@ const Leaf = (props: {
}, [placeholderRef])

let children = (
<String isLast={isLast} leaf={leaf} parent={parent} text={text} />
<String
key={keyForString++}
isLast={isLast}
leaf={leaf}
parent={parent}
text={text}
/>
)

if (leaf[PLACEHOLDER_SYMBOL]) {
Expand Down

0 comments on commit 6346527

Please sign in to comment.