1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 15:02:51 +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

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
fix forced update in TextString in case of double render

View File

@@ -59,17 +59,17 @@ const TextString = (props: { text: string; isTrailing?: boolean }) => {
const { text, isTrailing = false } = props const { text, isTrailing = false } = props
const ref = useRef<HTMLSpanElement>(null) const ref = useRef<HTMLSpanElement>(null)
const forceUpdateFlag = useRef(false) const forceUpdateCount = useRef(0)
if (ref.current && ref.current.textContent !== text) { 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 // 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 // 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. // match and not apply an update. Forces each render to actually reconcile.
return ( return (
<span data-slate-string ref={ref} key={forceUpdateFlag.current ? 'A' : 'B'}> <span data-slate-string ref={ref} key={forceUpdateCount.current}>
{text} {text}
{isTrailing ? '\n' : null} {isTrailing ? '\n' : null}
</span> </span>