[FIX] web,base: do not display js module errors in some cases

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 <ged@odoo.com>
This commit is contained in:
Géry Debongnie
2023-04-04 16:02:12 +02:00
parent 70a8758760
commit 44052d58d7
4 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ class TestQweb(TransactionCaseWithUserDemo):
<meta/>
<script type="text/javascript" src="http://test.external.link/javascript1.js"></script>
<script type="text/javascript" src="http://test.external.link/javascript2.js"></script>
<script type="text/javascript" src="http://test.cdn%(js)s" data-asset-bundle="%(asset_xmlid)s" data-asset-version="%(asset_version)s"></script>
<script type="text/javascript" src="http://test.cdn%(js)s" data-asset-bundle="%(asset_xmlid)s" data-asset-version="%(asset_version)s" onerror="__odooAssetError=1"></script>
</head>
<body>
<img src="http://test.external.link/img.png" loading="lazy"/>
+9
View File
@@ -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) {
+1
View File
@@ -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))
@@ -624,7 +624,7 @@ class TestJavascriptAssetsBundle(FileTouchable):
<meta/>
<script type="text/javascript" src="http://test.external.link/javascript1.js"></script>
<script type="text/javascript" src="http://test.external.link/javascript2.js"></script>
<script type="text/javascript" src="%(js)s" data-asset-bundle="%(asset_bundle_js)s" data-asset-version="%(asset_version_js)s"></script>
<script type="text/javascript" src="%(js)s" data-asset-bundle="%(asset_bundle_js)s" data-asset-version="%(asset_version_js)s" onerror="__odooAssetError=1"></script>
</head>
<body>
</body>
@@ -655,7 +655,7 @@ class TestJavascriptAssetsBundle(FileTouchable):
<meta/>
<script type="text/javascript" src="http://test.external.link/javascript1.js"></script>
<script type="text/javascript" src="http://test.external.link/javascript2.js"></script>
<script type="text/javascript" src="%(js)s" data-asset-bundle="%(asset_bundle_js)s" data-asset-version="%(asset_version_js)s"></script>
<script type="text/javascript" src="%(js)s" data-asset-bundle="%(asset_bundle_js)s" data-asset-version="%(asset_version_js)s" onerror="__odooAssetError=1"></script>
</head>
<body>
</body>