Details
-
Bug
-
Resolution: Fixed
-
Major
-
14.10.7
-
None
-
Unknown
-
N/A
-
N/A
-
Description
This is hard to reproduce but it can happen. Suppose you have a wiki page with a live table, e.g. the page index. Open this page and export it to PDF. The PDF export is supposed to wait for the live table to load before printing the Web page to PDF. But this is not always the case.
The live table is initialized on the dom:loaded event (well, actually xwiki:dom:loading which is triggered on dom:loaded) when it makes an XHR request to retrieve the live table results. The page-ready module should intercept this XHR request and delay the page ready until we receive the response. This page-ready module is one of the first being loaded, just after RequireJS, but since it uses RequireJS, its code is actually not executed right away (when the JavaScript code is loaded) but on the next event cycle (similar to a setTimeout(0)). As a result we have a race between dom:loaded event and the execution of page-ready module:
- Firefox seems to trigger dom:loaded before page-ready is executed, but only when the page is loaded in a normal browser window
- when the page is loaded in an iframe (like in the case of PDF export) the order is reversed
- Chrome seems to execute the page-ready module before triggering dom:loaded, both on a standard window and inside an iframe
As a result, the PDF export works for now as expected because:
- we either use an iframe (user's browser)
- or a head-less Chrome
but this can change anytime, so it's very fragile. We need to make sure that page-ready module is always executed before other JavaScript code can make an XHR / fetch request.