Phenomenon
When using document.execCommand('insertHTML', ...) to insert HTML content into a contenteditable region, the DOM structure may be broken or reformatted unexpectedly. Nested elements may be flattened or reorganized.
Reproduction example
- Create a contenteditable div.
- Select a position within it.
- Use
document.execCommand('insertHTML', false, '<p><strong>Bold text</strong></p>'). - Inspect the resulting DOM structure.
Observed behavior
- In Chrome on Windows,
insertHTMLmay break the DOM structure. - Nested elements may be flattened or reorganized.
- Formatting may be lost or changed unexpectedly.
Expected behavior
insertHTMLshould preserve the HTML structure as provided.- Nested elements should remain nested.
- Formatting should be maintained.