Fix Slate crash after inserting emoji from picker/autocomplete

This commit is contained in:
2026-07-13 02:40:02 +10:00
parent b711646b58
commit 687f139719
5 changed files with 53 additions and 21 deletions

View File

@@ -82,13 +82,21 @@ function RenderEmoticonElement({
const selected = useSelected();
const focused = useFocused();
// Void inline: attributes + contentEditable={false} on the same root, children
// as a sibling of the visual (not nested inside another non-editable span).
// Nesting {children} under an inner contentEditable={false} breaks Slate's
// DOM↔node map and crashes ReactEditor.focus after insert.
return (
<span className={css.EmoticonBase} {...attributes}>
<span
{...attributes}
contentEditable={false}
className={css.EmoticonBase}
style={{ userSelect: 'none' }}
>
<span
className={css.Emoticon({
focus: selected && focused,
})}
contentEditable={false}
>
{element.key.startsWith('mxc://') ? (
<img
@@ -99,8 +107,8 @@ function RenderEmoticonElement({
) : (
element.key
)}
{children}
</span>
{children}
</span>
);
}