fix: guard against destroyed editor in RichTextMessageEditor

This commit is contained in:
Kirill
2026-05-25 19:15:32 +05:00
parent 849e96511e
commit 69813b0fd0
2 changed files with 9 additions and 8 deletions
@@ -30,18 +30,19 @@ export function RichTextMessageEditor({
content: initialContent,
editable: !disabled,
onUpdate: ({ editor: tiptap }) => {
if (tiptap.isDestroyed) return
const plainText = tiptap.getText().trim()
onChange(plainText ? tiptap.getHTML() : '')
},
})
useEffect(() => {
if (!editor) return
if (!editor || editor.isDestroyed) return
editor.setEditable(!disabled)
}, [disabled, editor])
useEffect(() => {
if (!editor) return
if (!editor || editor.isDestroyed) return
const normalizedValue = value.trim() ? value : '<p></p>'
if (editor.getHTML() === normalizedValue) return
editor.commands.setContent(normalizedValue, { emitUpdate: false })
@@ -52,8 +53,8 @@ export function RichTextMessageEditor({
<Stack direction="row" spacing={0.5} sx={{ p: 0.75, borderBottom: 1, borderColor: 'divider' }}>
<IconButton
size="small"
onClick={() => editor?.chain().focus().toggleBold().run()}
color={editor?.isActive('bold') ? 'primary' : 'default'}
onClick={() => editor?.chain()?.focus().toggleBold().run()}
color={editor && !editor.isDestroyed && editor.isActive('bold') ? 'primary' : 'default'}
disabled={disabled}
aria-label="Жирный"
>
@@ -61,8 +62,8 @@ export function RichTextMessageEditor({
</IconButton>
<IconButton
size="small"
onClick={() => editor?.chain().focus().toggleItalic().run()}
color={editor?.isActive('italic') ? 'primary' : 'default'}
onClick={() => editor?.chain()?.focus().toggleItalic().run()}
color={editor && !editor.isDestroyed && editor.isActive('italic') ? 'primary' : 'default'}
disabled={disabled}
aria-label="Курсив"
>
@@ -70,8 +71,8 @@ export function RichTextMessageEditor({
</IconButton>
<IconButton
size="small"
onClick={() => editor?.chain().focus().toggleBulletList().run()}
color={editor?.isActive('bulletList') ? 'primary' : 'default'}
onClick={() => editor?.chain()?.focus().toggleBulletList().run()}
color={editor && !editor.isDestroyed && editor.isActive('bulletList') ? 'primary' : 'default'}
disabled={disabled}
aria-label="Список"
>
Binary file not shown.