From b10849182086699d4bb18209a37ea6247f712bd0 Mon Sep 17 00:00:00 2001 From: Jake Donham Date: Tue, 28 Sep 2021 10:19:47 -0700 Subject: [PATCH] fix forced update in TextString in case of double render (#4556) * fix forced update in TextString in case of double render * added changeset --- .changeset/smart-eyes-enjoy.md | 5 +++++ packages/slate-react/src/components/string.tsx | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/smart-eyes-enjoy.md diff --git a/.changeset/smart-eyes-enjoy.md b/.changeset/smart-eyes-enjoy.md new file mode 100644 index 000000000..414abbb78 --- /dev/null +++ b/.changeset/smart-eyes-enjoy.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +fix forced update in TextString in case of double render diff --git a/packages/slate-react/src/components/string.tsx b/packages/slate-react/src/components/string.tsx index c6a228b36..b8ee407fe 100644 --- a/packages/slate-react/src/components/string.tsx +++ b/packages/slate-react/src/components/string.tsx @@ -59,17 +59,17 @@ const TextString = (props: { text: string; isTrailing?: boolean }) => { const { text, isTrailing = false } = props const ref = useRef(null) - const forceUpdateFlag = useRef(false) + const forceUpdateCount = useRef(0) if (ref.current && ref.current.textContent !== text) { - forceUpdateFlag.current = !forceUpdateFlag.current + forceUpdateCount.current += 1 } // 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}