diff --git a/app/components/editor/Tiptap.tsx b/app/components/editor/Tiptap.tsx index a687746..8470c90 100644 --- a/app/components/editor/Tiptap.tsx +++ b/app/components/editor/Tiptap.tsx @@ -1,5 +1,5 @@ 'use client'; -import { useEffect } from 'react'; +import { useEffect, useRef } from 'react'; import { EditorContent, useEditor } from '@tiptap/react'; import StarterKit from '@tiptap/starter-kit'; import Underline from '@tiptap/extension-underline'; @@ -9,11 +9,16 @@ const Tiptap: React.FC<{ onChange: (newContent: string) => void; content: string; }> = ({ onChange, content }) => { + const lastAppliedContentRef = useRef(content); + const handleChange = (newContent: string) => { + lastAppliedContentRef.current = newContent; onChange(newContent); }; + const editor = useEditor({ extensions: [StarterKit, Underline], + content, editorProps: { attributes: { class: @@ -24,12 +29,13 @@ const Tiptap: React.FC<{ handleChange(editor.getHTML()); }, }); + useEffect(() => { if (!editor) return; - const value = content; - if (value) { - editor.commands.setContent(value); - } + if (content === lastAppliedContentRef.current) return; + + editor.commands.setContent(content, false); + lastAppliedContentRef.current = content; }, [editor, content]); return (