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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user