From 06e583e1fde6da956a5126cae246e0e1a3d6d69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Tue, 26 Jan 2016 14:20:54 +0100 Subject: [PATCH] [FIX] web: change qweb to work around phantomjs bug This commit does not actually fix qweb2.js, but it works around a phantomjs bug. The problem with phantomjs is that in some situations, the xmlhttprequests are dropped with a status 0. It is most likely related to the issue: https://github.com/ariya/phantomjs/issues/11195 In our testing framework, it seems to appear when requests sent before the 'load' event of phantomjs are received after, and also when those requests are listened with the onreadystatechange handler. The bug does not appear if we use addEventListener with the 'load' event (at least, not for a few builds) This commit does not worsen qweb, and it is also a small improvement in style (in my opinion). --- addons/web/static/lib/qweb/qweb2.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js index ee1876d9f4f..1cfc7bb69ef 100644 --- a/addons/web/static/lib/qweb/qweb2.js +++ b/addons/web/static/lib/qweb/qweb2.js @@ -295,15 +295,13 @@ QWeb2.Engine = (function() { } req.open('GET', s, async); if (async) { - req.onreadystatechange = function() { - if (req.readyState == 4) { - if (req.status == 200) { - callback(null, self._parse_from_request(req)); - } else { - callback(new Error("Can't load template " + s + ", http status " + req.status)); - } + req.addEventListener("load", function() { + if (req.status == 200) { + callback(null, self._parse_from_request(req)); + } else { + callback(new Error("Can't load template " + s + ", http status " + req.status)); } - }; + }); } req.send(null); if (!async) {