From dcf6f8ef3cde95f2057a4bf12467398acc8b6894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 6 Oct 2022 09:47:22 +0000 Subject: [PATCH] [REF] web_editor: lazyload html2canvas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, the html2canvas library was loaded in the assets_common bundle, which is in turn loaded by pretty much all odoo users. Since it is a big library, and it is only used in two different cases, it makes sense to lazy load it. The call in convert_inline.js has been adapted. It is however also added to the point of sale bundle, and could probably be lazy loaded as well. closes odoo/odoo#102490 X-original-commit: 3d94b0212d2b7f4d412a578055de42e3f88058eb Signed-off-by: David Monjoie (dmo) Signed-off-by: Géry Debongnie --- addons/web_editor/__manifest__.py | 1 - addons/web_editor/static/src/js/backend/convert_inline.js | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/__manifest__.py b/addons/web_editor/__manifest__.py index 62c368283f3..f59d5bf2720 100644 --- a/addons/web_editor/__manifest__.py +++ b/addons/web_editor/__manifest__.py @@ -30,7 +30,6 @@ Odoo Web Editor widget. 'web_editor/static/lib/jQuery.transfo.js', 'web/static/lib/nearest/jquery.nearest.js', 'web_editor/static/lib/webgl-image-filter/webgl-image-filter.js', - 'web_editor/static/lib/html2canvas.js', # needed for convert_inline.js 'web_editor/static/lib/DOMPurify.js', # odoo-editor 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 158d7566100..a6344dee577 100644 --- a/addons/web_editor/static/src/js/backend/convert_inline.js +++ b/addons/web_editor/static/src/js/backend/convert_inline.js @@ -2,6 +2,8 @@ 'use strict'; import { isBlock, rgbToHex } from '../editor/odoo-editor/src/utils/utils'; +import { loadJS } from '@web/core/assets'; + /* global html2canvas */ //-------------------------------------------------------------------------- @@ -631,6 +633,7 @@ async function toInline($editable, cssRules, $iframe) { * @param {Element} editable */ async function flattenBackgroundImages(editable) { + await loadJS('/web_editor/static/lib/html2canvas.js'); for (const backgroundImage of editable.querySelectorAll('*[style*=background-image]')) { if (backgroundImage.parentElement) { // If the image was nested, we removed it already. const canvas = await html2canvas(backgroundImage);