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.
This commit is contained in:
Dwindi Ramadhana
2026-01-01 01:19:55 +07:00
parent 8bd2713385
commit 861c45638b

View File

@@ -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);
}
}