readium / readium-js-viewer

👁 ReadiumJS viewer: default web app for Readium.js library
BSD 3-Clause "New" or "Revised" License
550 stars 186 forks source link

[Firefox only] RequireJS "no optimize" (raw source tree, instead of single/multiple bundle) => race conditions to fetch async AMD modules? #696

Open danielweck opened 6 years ago

danielweck commented 6 years ago

npm run http =>

Loading failed for the <script> with source “http://127.0.0.1:8080/src/js/analytics/Analytics.js”.
index_RequireJS_no-optimize.html
Error: Script error for "Analytics", needed by: readium_js_viewer/EpubLibrary, readium_js_viewer/EpubReader
http://requirejs.org/docs/errors.html#scripterror
danielweck commented 6 years ago

Note that RequireJS dynamically injects the following markup into the head of index_RequireJS_no-optimize.html:

<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="readium_shared_js/globalsSetup" src="../readium-js/readium-shared-js/js/globalsSetup.js"></script>
...
...
... (many more)

Note the async attribute, and compare with the "hard-coded" includes in index_RequireJS_no-optimize.html:

https://github.com/readium/readium-js-viewer/blob/develop/dev/index_RequireJS_no-optimize.html#L40-L52

https://github.com/readium/readium-js-viewer/blob/0b10675a8b7f0cb80a76c88020e0dd3cd00dd6a3/dev/index_RequireJS_no-optimize.html#L40-L53

danielweck commented 6 years ago

Note that the removal of Rangy does not affect this behaviour ( https://github.com/readium/readium-shared-js/issues/445 )

danielweck commented 6 years ago

The above bug report is with Firefox. With Chrome (where this but does not exist), the RequireJS-injected markup looks slightly different, in the sense that the async attribute has no value (equivalent to async="async"), whereas in Firefox is seems to be async="" (I'm not actually sure this makes any difference at all in the in-memory DOM, maybe this is just how markup is rendered in the debugger):

<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="readium_shared_js/globalsSetup" src="../readium-js/readium-shared-js/js/globalsSetup.js"></script>
danielweck commented 6 years ago

Safari on MacOS works fine too (the async attribute is reported by the Web Inspector / DOM debugger just as with Chrome). So this bug seems to only occur in Firefox.

Praveen188 commented 5 years ago

@danielweck In the Firefox reader is not working not loading an epub file.