[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
This commit is contained in:
Antoine Guenet
2023-02-03 10:35:53 +01:00
parent 32a7c01a5c
commit 8a6337f15b
2 changed files with 6 additions and 2 deletions
@@ -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
@@ -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);