From 8852f6258043926ced4fd8369f8d175965baa98f Mon Sep 17 00:00:00 2001
From: parsa aghaei
Date: Mon, 24 Aug 2026 13:40:25 +0330
Subject: [PATCH] fix(admin-panel): resolve caret jumping and DOM sync issues
in RichTextEditor
---
.../src/components/ui/RichTextEditor.tsx | 27 +-
graphify-out/cache/stat-index.json | 2 +-
graphify-out/manifest.json | 1174 ++++++++---------
3 files changed, 613 insertions(+), 590 deletions(-)
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({