[FIX] web_editor: breaking _onBeforeUnload when canceling edition
After updating mass_mailing_snippets_menu_tabs to cancel the
template's edition at the end of the tour, the editor starts blowing
up during cleanup with:
```
Trying to set result to failed (UncaughtTypeError: Cannot read properties of null (reading 'anchorNode')
at Sanitize._parse (/web/assets/363-d1667a2/web_editor.assets_wysiwyg.min.js:1453:105)
at Sanitize.parse (/web/assets/363-d1667a2/web_editor.assets_wysiwyg.min.js:1450:6)
at new Sanitize (/web/assets/363-d1667a2/web_editor.assets_wysiwyg.min.js:1448:6)
at sanitize (/web/assets/363-d1667a2/web_editor.assets_wysiwyg.min.js:1460:53)
at OdooEditor.cleanForSave (/web/assets/363-d1667a2/web_editor.assets_wysiwyg.min.js:1372:37)
at Class.getValue (/web/assets/363-d1667a2/web_editor.assets_wysiwyg.min.js:2547:1121)
at Class.isDirty (/web/assets/363-d1667a2/web_editor.assets_wysiwyg.min.js:2547:407)
at
_onBeforeUnload (/web/assets/363-d1667a2/web_editor.assets_wysiwyg.min.js:2509:560)
```
After consultation with the relevant team, there are edition contexts
where it's perfectly valid to have no "live" selection for one reason
or an other, so this should be fixed.
Ideally the field should also properly be discarded such that the
event listener is removed and the callback is never called at all,
however the legacy client has no such hook at the field level (the
controller seems to be the lowest).
closes odoo/odoo#96517
Related: odoo/documentation#2550
Related: odoo/enterprise#29824
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
@@ -1686,7 +1686,7 @@ export class OdooEditor extends EventTarget {
|
||||
*/
|
||||
_computeHistorySelection() {
|
||||
const sel = this.document.getSelection();
|
||||
if (!sel.anchorNode) {
|
||||
if (!(sel && sel.anchorNode)) {
|
||||
return this._latestComputedSelection;
|
||||
}
|
||||
this._latestComputedSelection = {
|
||||
|
||||
@@ -123,7 +123,8 @@ class Sanitize {
|
||||
node = nodeP;
|
||||
}
|
||||
|
||||
const anchor = this.root.ownerDocument.getSelection().anchorNode;
|
||||
const selection = this.root.ownerDocument.getSelection();
|
||||
const anchor = selection && selection.anchorNode;
|
||||
const anchorEl = anchor && closestElement(anchor);
|
||||
// Remove zero-width spaces added by `fillEmpty` when there is
|
||||
// content and the selection is not next to it.
|
||||
|
||||
Reference in New Issue
Block a user