diff --git a/frontend/admin-panel/src/components/ui/RichTextEditor.tsx b/frontend/admin-panel/src/components/ui/RichTextEditor.tsx index 1d0ccc10..37d18539 100644 --- a/frontend/admin-panel/src/components/ui/RichTextEditor.tsx +++ b/frontend/admin-panel/src/components/ui/RichTextEditor.tsx @@ -1,4 +1,4 @@ -import React, { useRef } from 'react'; +import React, { useRef, useEffect } from 'react'; import { Bold, Italic, @@ -41,6 +41,25 @@ export default function RichTextEditor({ className = '', }: RichTextEditorProps) { const editorRef = useRef(null); + const isTypingRef = useRef(false); + const isMountedRef = useRef(false); + + // Sync value from props on initial mount or when external change occurs (not while active) + useEffect(() => { + if (!editorRef.current) return; + if (!isMountedRef.current) { + editorRef.current.innerHTML = value || ''; + isMountedRef.current = true; + return; + } + + // Only update innerHTML if it's different and not currently focused/typing + if (editorRef.current.innerHTML !== (value || '')) { + if (!isTypingRef.current && document.activeElement !== editorRef.current) { + editorRef.current.innerHTML = value || ''; + } + } + }, [value]); const exec = (command: string, val: string | undefined = undefined) => { document.execCommand(command, false, val); @@ -58,7 +77,11 @@ export default function RichTextEditor({ const handleInput = () => { if (editorRef.current) { + isTypingRef.current = true; onChange(editorRef.current.innerHTML); + setTimeout(() => { + isTypingRef.current = false; + }, 50); } }; @@ -228,8 +251,8 @@ export default function RichTextEditor({