From 8a6337f15be2549e0c99df62df077eeaebc4f686 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Tue, 31 Jan 2023 14:11:48 +0000 Subject: [PATCH] [FIX] web_editor: move rules cache from document to wysiwyg instance The CSS rules cache for convert_inline was stored on the edited document, which is problematic since OWL destroys the document where we used to just hide it (eg, when switching tabs in the form view). X-original-commit: d432ebbddae7192eca7215a8489abb3ad91a45f2 Part-of: odoo/odoo#111778 --- addons/web_editor/static/src/js/backend/convert_inline.js | 7 +++++-- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/backend/convert_inline.js b/addons/web_editor/static/src/js/backend/convert_inline.js index 0889c929733..4d1745903a8 100644 --- a/addons/web_editor/static/src/js/backend/convert_inline.js +++ b/addons/web_editor/static/src/js/backend/convert_inline.js @@ -552,11 +552,14 @@ async function toInline($editable, cssRules, $iframe) { $editable.removeClass('odoo-editor-editable'); const editable = $editable.get(0); const iframe = $iframe && $iframe.get(0); + const wysiwyg = $editable.data('wysiwyg'); const doc = editable.ownerDocument; - cssRules = cssRules || doc._rulesCache; + cssRules = cssRules || wysiwyg && wysiwyg._rulesCache; if (!cssRules) { cssRules = getCSSRules(doc); - doc._rulesCache = cssRules; + if (wysiwyg) { + wysiwyg._rulesCache = cssRules; + } } // If the editable is not visible, we need to make it visible in order to diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 7b609bbb685..ad8ff8eb198 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -2548,6 +2548,7 @@ const Wysiwyg = Widget.extend({ } const {collaborationChannel} = this.options; this._stopPeerToPeer(); + this._rulesCache = undefined; // Reset the cache of rules. // If there is no collaborationResId, the record has been deleted. if (!collaborationChannel || !collaborationChannel.collaborationResId) { this.setValue(value);