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

Double character insert regression (#4460)

* fix double character regression

* add changeset
This commit is contained in:
Dylan Schiemann
2021-08-19 07:49:17 -07:00
committed by GitHub
parent 2fa928103d
commit ace397f966
2 changed files with 22 additions and 23 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
fix double character insertion regression due to unnecessary memo

View File

@@ -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<HTMLSpanElement>(null)
const forceUpdateFlag = useRef(false)
const ref = useRef<HTMLSpanElement>(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 (
<span
data-slate-string
ref={ref}
key={forceUpdateFlag.current ? 'A' : 'B'}
>
{text}
{isTrailing ? '\n' : null}
</span>
)
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 (
<span data-slate-string ref={ref} key={forceUpdateFlag.current ? 'A' : 'B'}>
{text}
{isTrailing ? '\n' : null}
</span>
)
}
/**
* Leaf strings without text, render as zero-width strings.