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:
5
.changeset/smart-eyes-enjoy.md
Normal file
5
.changeset/smart-eyes-enjoy.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix forced update in TextString in case of double render
|
@@ -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>
|
||||||
|
Reference in New Issue
Block a user