From ace397f96602d93ab9216e3d3434f55eef981e4d Mon Sep 17 00:00:00 2001 From: Dylan Schiemann Date: Thu, 19 Aug 2021 07:49:17 -0700 Subject: [PATCH] Double character insert regression (#4460) * fix double character regression * add changeset --- .changeset/nine-windows-rush.md | 5 +++ .../slate-react/src/components/string.tsx | 40 ++++++++----------- 2 files changed, 22 insertions(+), 23 deletions(-) create mode 100644 .changeset/nine-windows-rush.md diff --git a/.changeset/nine-windows-rush.md b/.changeset/nine-windows-rush.md new file mode 100644 index 000000000..254501d03 --- /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 7ecbd1e15..c6a228b36 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.