summaryrefslogtreecommitdiff
path: root/addons/web_editor
diff options
context:
space:
mode:
authorBenoit Socias <bso@odoo.com>2021-02-08 13:01:27 +0000
committerqsm-odoo <qsm@odoo.com>2021-02-15 15:57:00 +0000
commit9aeba7dec95b397ef894f5a181920dff269d6ad4 (patch)
tree6c16951e5b7627b5f00d18d0d4fe51a1dc24726b /addons/web_editor
parent7f19f63b18bc7d17a393b3535492c7f90595ca39 (diff)
[IMP] web_editor: instantiate color palette only when necessary
Color palette are only visible once they are opened. However, we instantiate them a lot to build the "options" editor panel which caused the editor to appear buggy for some users... even if they would never open a colorpalette. This fixes that issue. The fix is not entirely stable but was made as stable as possible... better implementation will be done in master. task-2439295 https://github.com/odoo/odoo/pull/65223 closes odoo/odoo#65223 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com> Co-authored-by: qsm-odoo <qsm@odoo.com>
Diffstat (limited to 'addons/web_editor')
-rw-r--r--addons/web_editor/static/src/js/editor/snippets.options.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js
index 7496eb29018..9b3baae8f8e 100644
--- a/addons/web_editor/static/src/js/editor/snippets.options.js
+++ b/addons/web_editor/static/src/js/editor/snippets.options.js
@@ -1241,8 +1241,12 @@ const ColorpickerUserValueWidget = SelectUserValueWidget.extend({
const _super = this._super.bind(this);
const args = arguments;
- // Pre-instanciate the color palette widget
- await this._renderColorPalette();
+ // TODO review in master, this was done in stable to keep the speed fix
+ // as stable as possible (to have a reference to a widget even if not a
+ // colorPalette widget).
+ this.colorPalette = new Widget(this);
+ this.colorPalette.getColorNames = () => [];
+ await this.colorPalette.appendTo(document.createDocumentFragment());
// Build the select element with a custom span to hold the color preview
this.colorPreviewEl = document.createElement('span');
@@ -1260,6 +1264,22 @@ const ColorpickerUserValueWidget = SelectUserValueWidget.extend({
/**
* @override
*/
+ open: function () {
+ if (this.colorPalette.setSelectedColor) {
+ this.colorPalette.setSelectedColor(this._value);
+ } else {
+ // TODO review in master, this does async stuff. Maybe the open
+ // method should now be async. This is not really robust as the
+ // colorPalette can be used without it to be fully rendered but
+ // the use of the saved promise where we can should mitigate that
+ // issue.
+ this._colorPaletteRenderPromise = this._renderColorPalette();
+ }
+ this._super(...arguments);
+ },
+ /**
+ * @override
+ */
close: function () {
this._super(...arguments);
if (this._customColorValue && this._customColorValue !== this._value) {
@@ -1320,7 +1340,7 @@ const ColorpickerUserValueWidget = SelectUserValueWidget.extend({
async setValue(color) {
await this._super(...arguments);
- this.colorPalette.setSelectedColor(this._value);
+ await this._colorPaletteRenderPromise;
const classes = weUtils.computeColorClasses(this.colorPalette.getColorNames());
this.colorPreviewEl.classList.remove(...classes);