diff --git a/frontend/src/components/stories/RichTextEditor.tsx b/frontend/src/components/stories/RichTextEditor.tsx index 7a33cc4..4005d58 100644 --- a/frontend/src/components/stories/RichTextEditor.tsx +++ b/frontend/src/components/stories/RichTextEditor.tsx @@ -148,11 +148,15 @@ export default function RichTextEditor({ const tempDiv = document.createElement('div'); tempDiv.innerHTML = sanitizedHtml; - // Insert the nodes from the temporary container + // Create a document fragment to insert all nodes at once + const fragment = document.createDocumentFragment(); while (tempDiv.firstChild) { - range.insertNode(tempDiv.firstChild); + fragment.appendChild(tempDiv.firstChild); } + // Insert the entire fragment at once to preserve order + range.insertNode(fragment); + // Move cursor to end of inserted content range.collapse(false); selection.removeAllRanges();