diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index 8b7e6cfd0e9..172d0c92d83 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -3580,6 +3580,12 @@ export class OdooEditor extends EventTarget { */ _onSelectionChange() { const selection = this.document.getSelection(); + if (!selection) { + // Because the `selectionchange` event is async, the selection can + // be null if the node has been removed between the moment the + // selection was moved and the moment the event is triggered. + return; + } const anchorNode = selection.anchorNode; if (anchorNode && closestElement(anchorNode, '[data-oe-protected="true"]')) { return;