From 861c45638b8ab945bfae41a5b75ffe57fd8a1eaa Mon Sep 17 00:00:00 2001 From: Dwindi Ramadhana Date: Thu, 1 Jan 2026 01:19:55 +0700 Subject: [PATCH] fix: resolve dialog freeze caused by infinite loop in RichTextEditor The RichTextEditor useEffect was comparing raw content with editor HTML, but they differed due to whitespace normalization (e.g., '\n\n' vs ''). This caused continuous setContent calls, freezing the edit dialog. Fixed by normalizing whitespace in both strings before comparison. --- admin-spa/src/components/ui/rich-text-editor.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/admin-spa/src/components/ui/rich-text-editor.tsx b/admin-spa/src/components/ui/rich-text-editor.tsx index 4c0bbee..4e39421 100644 --- a/admin-spa/src/components/ui/rich-text-editor.tsx +++ b/admin-spa/src/components/ui/rich-text-editor.tsx @@ -94,9 +94,12 @@ export function RichTextEditor({ useEffect(() => { if (editor && content) { const currentContent = editor.getHTML(); - // Only update if content is different (avoid infinite loops) - if (content !== currentContent) { - console.log('RichTextEditor: Updating content', { content, currentContent }); + // Normalize whitespace before comparing to avoid infinite loops + // The editor normalizes HTML, so "\n" becomes "" in output + const normalizedContent = content.replace(/\s+/g, ' ').trim(); + const normalizedCurrent = currentContent.replace(/\s+/g, ' ').trim(); + + if (normalizedContent !== normalizedCurrent) { editor.commands.setContent(content); } }