fix: guard against destroyed editor in RichTextMessageEditor
This commit is contained in:
@@ -30,18 +30,19 @@ export function RichTextMessageEditor({
|
|||||||
content: initialContent,
|
content: initialContent,
|
||||||
editable: !disabled,
|
editable: !disabled,
|
||||||
onUpdate: ({ editor: tiptap }) => {
|
onUpdate: ({ editor: tiptap }) => {
|
||||||
|
if (tiptap.isDestroyed) return
|
||||||
const plainText = tiptap.getText().trim()
|
const plainText = tiptap.getText().trim()
|
||||||
onChange(plainText ? tiptap.getHTML() : '')
|
onChange(plainText ? tiptap.getHTML() : '')
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!editor) return
|
if (!editor || editor.isDestroyed) return
|
||||||
editor.setEditable(!disabled)
|
editor.setEditable(!disabled)
|
||||||
}, [disabled, editor])
|
}, [disabled, editor])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!editor) return
|
if (!editor || editor.isDestroyed) return
|
||||||
const normalizedValue = value.trim() ? value : '<p></p>'
|
const normalizedValue = value.trim() ? value : '<p></p>'
|
||||||
if (editor.getHTML() === normalizedValue) return
|
if (editor.getHTML() === normalizedValue) return
|
||||||
editor.commands.setContent(normalizedValue, { emitUpdate: false })
|
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' }}>
|
<Stack direction="row" spacing={0.5} sx={{ p: 0.75, borderBottom: 1, borderColor: 'divider' }}>
|
||||||
<IconButton
|
<IconButton
|
||||||
size="small"
|
size="small"
|
||||||
onClick={() => editor?.chain().focus().toggleBold().run()}
|
onClick={() => editor?.chain()?.focus().toggleBold().run()}
|
||||||
color={editor?.isActive('bold') ? 'primary' : 'default'}
|
color={editor && !editor.isDestroyed && editor.isActive('bold') ? 'primary' : 'default'}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
aria-label="Жирный"
|
aria-label="Жирный"
|
||||||
>
|
>
|
||||||
@@ -61,8 +62,8 @@ export function RichTextMessageEditor({
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<IconButton
|
||||||
size="small"
|
size="small"
|
||||||
onClick={() => editor?.chain().focus().toggleItalic().run()}
|
onClick={() => editor?.chain()?.focus().toggleItalic().run()}
|
||||||
color={editor?.isActive('italic') ? 'primary' : 'default'}
|
color={editor && !editor.isDestroyed && editor.isActive('italic') ? 'primary' : 'default'}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
aria-label="Курсив"
|
aria-label="Курсив"
|
||||||
>
|
>
|
||||||
@@ -70,8 +71,8 @@ export function RichTextMessageEditor({
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<IconButton
|
||||||
size="small"
|
size="small"
|
||||||
onClick={() => editor?.chain().focus().toggleBulletList().run()}
|
onClick={() => editor?.chain()?.focus().toggleBulletList().run()}
|
||||||
color={editor?.isActive('bulletList') ? 'primary' : 'default'}
|
color={editor && !editor.isDestroyed && editor.isActive('bulletList') ? 'primary' : 'default'}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
aria-label="Список"
|
aria-label="Список"
|
||||||
>
|
>
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user