diff --git a/.changeset/nine-windows-rush.md b/.changeset/nine-windows-rush.md new file mode 100644 index 0000000000..254501d03f --- /dev/null +++ b/.changeset/nine-windows-rush.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +fix double character insertion regression due to unnecessary memo diff --git a/packages/slate-react/src/components/string.tsx b/packages/slate-react/src/components/string.tsx index 7ecbd1e158..c6a228b367 100644 --- a/packages/slate-react/src/components/string.tsx +++ b/packages/slate-react/src/components/string.tsx @@ -55,32 +55,26 @@ const String = (props: { /** * Leaf strings with text in them. */ -const TextString = React.memo( - (props: { text: string; isTrailing?: boolean }) => { - const { text, isTrailing = false } = props +const TextString = (props: { text: string; isTrailing?: boolean }) => { + const { text, isTrailing = false } = props - const ref = useRef(null) - const forceUpdateFlag = useRef(false) + const ref = useRef(null) + const forceUpdateFlag = useRef(false) - if (ref.current && ref.current.textContent !== text) { - forceUpdateFlag.current = !forceUpdateFlag.current - } - - // This component may have skipped rendering due to native operations being - // applied. If an undo is performed React will see the old and new shadow DOM - // match and not apply an update. Forces each render to actually reconcile. - return ( - - {text} - {isTrailing ? '\n' : null} - - ) + if (ref.current && ref.current.textContent !== text) { + forceUpdateFlag.current = !forceUpdateFlag.current } -) + + // This component may have skipped rendering due to native operations being + // applied. If an undo is performed React will see the old and new shadow DOM + // match and not apply an update. Forces each render to actually reconcile. + return ( + + {text} + {isTrailing ? '\n' : null} + + ) +} /** * Leaf strings without text, render as zero-width strings.