From 36994a6616fae35b702c6bb9f1ed3779ece66fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Tue, 26 Jan 2016 16:06:29 +0100 Subject: [PATCH] [FIX] web: load async js modules as soon as possible The module system allow modules to return a deferred. When that deferred resolves, the module is considered to have succesfully loaded, and the result value is its value. Then, the boot.js code used a setTimeout (via _.defer) to load all its dependencies. This is not wrong per se, but it empties the call stack, which give other code the opportunity to interfere. In particular, it is an issue in phantomjs tests, because it causes a window between the domcontentloaded event (which is a key event in website) and the actual loading of all dependent modules. This execution window can be used to start some tours, but the code of those tours is waiting the next tick to load, so horrible crashes happens. This commit calls immediately process_jobs to avoid those issues. --- addons/web/static/src/js/boot.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js index 77115499b46..34abca7ef03 100644 --- a/addons/web/static/src/js/boot.js +++ b/addons/web/static/src/js/boot.js @@ -203,24 +203,29 @@ function process_job (job) { var require = make_require(job); + + var job_exec; + var def = $.Deferred(); try { - var def = $.Deferred(); - $.when(job.factory.call(null, require)).then( - function (data) { - services[job.name] = data; - clearTimeout(time); - time = _.defer(odoo.process_jobs, jobs, services); - def.resolve(); - }, function (e) { - job.rejected = e || true; - jobs.push(job); - def.resolve(); - }); + job_exec = job.factory.call(null, require); jobs.splice(jobs.indexOf(job), 1); job_deferred.push(def); } catch (e) { job.error = e; } + if (!job.error) { + $.when(job_exec).then( + function (data) { + services[job.name] = data; + def.resolve(); + odoo.process_jobs(jobs, services); + }, function (e) { + job.rejected = e || true; + jobs.push(job); + def.resolve(); + } + ); + } } function is_ready (job) {