1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-19 13:41:19 +02:00

fix forced update in TextString in case of double render (#4556)

* fix forced update in TextString in case of double render

* added changeset
This commit is contained in:
Jake Donham
2021-09-28 10:19:47 -07:00
committed by GitHub
parent f04cc58270
commit b108491820
2 changed files with 8 additions and 3 deletions

View File

@@ -59,17 +59,17 @@ const TextString = (props: { text: string; isTrailing?: boolean }) => {
const { text, isTrailing = false } = props
const ref = useRef<HTMLSpanElement>(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 (
<span data-slate-string ref={ref} key={forceUpdateFlag.current ? 'A' : 'B'}>
<span data-slate-string ref={ref} key={forceUpdateCount.current}>
{text}
{isTrailing ? '\n' : null}
</span>