From 44052d58d7ccca5eaba38bb910d201dba5d0fde0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 3 Apr 2023 08:37:39 +0000 Subject: [PATCH] [FIX] web,base: do not display js module errors in some cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since saas 16.1, we added a more visible error information box when the module system cannot find some dependencies, or if there is an error in the JS code. This error box is very useful to understand a lot of typical devlopment issues. However, it was occasionally displayed in production code. However, we sometimes observe that the error information box was displayed, because the request to load an assets failed with a 404. It is unclear in which circumstance this can happen, but it seems that the following elements are involved: - the user has an open tab with odoo, kept open for a while - some js code is changed on the server, which causes the previous assets to be deleted - the user reload its open tabs, so the browser will load the /web page from disk, which points to the old assets files - then it will try to load all assets, with a 404 on one of the script - the error information box is displayed This commit intercepts the loading error and stop displaying the error information box, which is basically the same behaviour as 16.0 and before. We could force a reload in that case, but it seems dangerous, since in case of errors, it could easily lead to an infinite loop. closes odoo/odoo#117625 X-original-commit: 0a44b5b1e008b591a716efd26217c7db7360c37b Signed-off-by: Géry Debongnie --- addons/test_website/tests/test_qweb.py | 2 +- addons/web/static/src/boot.js | 9 +++++++++ odoo/addons/base/models/assetsbundle.py | 1 + odoo/addons/test_assetsbundle/tests/test_assetsbundle.py | 4 ++-- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/addons/test_website/tests/test_qweb.py b/addons/test_website/tests/test_qweb.py index aab35f16da1..e498232e09a 100644 --- a/addons/test_website/tests/test_qweb.py +++ b/addons/test_website/tests/test_qweb.py @@ -62,7 +62,7 @@ class TestQweb(TransactionCaseWithUserDemo): - + diff --git a/addons/web/static/src/boot.js b/addons/web/static/src/boot.js index 22d71a145bd..438d2e485d1 100644 --- a/addons/web/static/src/boot.js +++ b/addons/web/static/src/boot.js @@ -406,6 +406,15 @@ } function displayModuleErrors({ failed, missing, unloaded, cycle }) { + if (window.__odooAssetError) { + // this flag is set when we have an error loading the script for an + // asset. We sometimes see a 404, probably due to the fact that the + // attachment has been deleted. It is unclear in which circumstances + // it can happen, but we sometimes observe it. We could here force a + // reload, but it seems dangerous, since in case of errors, this + // could easily lead to an infinite loop. + return; + } const list = (heading, arr) => { const frag = document.createDocumentFragment(); if (!arr || !arr.length) { diff --git a/odoo/addons/base/models/assetsbundle.py b/odoo/addons/base/models/assetsbundle.py index 2eca5ec3d7a..e7983615773 100644 --- a/odoo/addons/base/models/assetsbundle.py +++ b/odoo/addons/base/models/assetsbundle.py @@ -196,6 +196,7 @@ class AssetsBundle(object): ["data-src" if lazy_load else "src", src], ['data-asset-bundle', self.name], ['data-asset-version', self.version], + ['onerror', '__odooAssetError=1'] ]) response.append(("script", attr, None)) diff --git a/odoo/addons/test_assetsbundle/tests/test_assetsbundle.py b/odoo/addons/test_assetsbundle/tests/test_assetsbundle.py index 0937ff1f2cb..5c8a96ca0aa 100644 --- a/odoo/addons/test_assetsbundle/tests/test_assetsbundle.py +++ b/odoo/addons/test_assetsbundle/tests/test_assetsbundle.py @@ -624,7 +624,7 @@ class TestJavascriptAssetsBundle(FileTouchable): - + @@ -655,7 +655,7 @@ class TestJavascriptAssetsBundle(FileTouchable): - +