mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-14 11:14:04 +02:00
Double character insert regression (#4460)
* fix double character regression * add changeset
This commit is contained in:
5
.changeset/nine-windows-rush.md
Normal file
5
.changeset/nine-windows-rush.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix double character insertion regression due to unnecessary memo
|
@@ -55,32 +55,26 @@ const String = (props: {
|
|||||||
/**
|
/**
|
||||||
* Leaf strings with text in them.
|
* Leaf strings with text in them.
|
||||||
*/
|
*/
|
||||||
const TextString = React.memo(
|
const TextString = (props: { text: string; isTrailing?: boolean }) => {
|
||||||
(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 forceUpdateFlag = useRef(false)
|
||||||
|
|
||||||
if (ref.current && ref.current.textContent !== text) {
|
if (ref.current && ref.current.textContent !== text) {
|
||||||
forceUpdateFlag.current = !forceUpdateFlag.current
|
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>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
// 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.
|
* Leaf strings without text, render as zero-width strings.
|
||||||
|
Reference in New Issue
Block a user