Symptom
Opening a new Page: page in the edit view for the first time -- i.e. when the page's thumbnail has never been rendered before -- shows a blank pane where the scan
should be. The browser's network log shows the image request completing with HTTP 200. Reloading the page usually fixes it, but the experience is annoying.
Example (any never-yet-rendered page of a large DjVu will do):
https://zh.wikisource.org/w/index.php?title=Page:文淵閣四庫全書_XXXX冊.djvu/Y&action=edit
(replace the two numbers for random for a repro; in general, book number XXXX is between 0001 and 1500, and page number Y is between 1 and 900).
For example:
- https://zh.wikisource.org/w/index.php?title=Page:文淵閣四庫全書_1234冊.djvu/56&action=edit
- https://zh.wikisource.org/w/index.php?title=Page:文淵閣四庫全書_1235冊.djvu/789&action=edit
(try something else if these links has been recently opened by someone viewing this bug.)
This symptom looks similar to T341742: Wikisource page images don't always display due to OpenSeadragon timeout and T423548: Page images disappearing on edit, but both are fixed and neither is this root cause (see below).
Root cause
modules/page/OpenseadragonController.js builds the viewer from the page image's currentSrc:
tileSources: { type: 'image', url: this.img.currentSrc, buildPyramid: false }
However, currentSrc is only populated once the image response starts arriving.
initialize() neither checks img.complete nor listens for the img's load event, so there is a race between the ResourceLoader modules and the thumbnail:
- First-ever view: the thumbnail does not exist yet, and Thumbor takes seconds to render a DjVu page (T337649: Thumbor fails to render thumbnails of djvu/tiff/pdf files quite often in eqiad); the module always wins the race. currentSrc is still "", OpenSeadragon is created with an empty URL, and there is no code path that ever retries. The server-rendered <img> is hidden by $img.hide(), so when its request completes (the 200 in the network log) nothing consumes it. The pane stays blank until a reload.
- Subsequent views: the thumbnail comes from cache in ~100 ms, the img wins the race, everything works. This is why the bug is reliably "first load only".
Reproduced in a scripted browser by delaying the thumbnail response by 12s: initialize() ran with currentSrc === "" and complete === false; the viewer fired open but its item never became fully loaded; the img's 200 arrived at t=12.5 s and was never used.
Control experiment: making the first thumbnail request fail fast (429) self-heals -- OSD got a non-empty currentSrc and successfully re-requested the URL itself. Only the slow-but-successful case blanks permanently, which is exactly the cold-Thumbor profile.
Related tickets, and why this one is not a duplicate
- T341742: Wikisource page images don't always display due to OpenSeadragon timeout fixed the OSD load timeout (30 s → 2 min). A timeout only helps when OSD has a URL and is waiting on it; here it never gets a URL, so there is nothing to time out.
- T423548: Page images disappearing on edit fixed a WebGL/CORS rendering failure; the drawer: 'canvas' workaround is deployed and this still reproduces.
- T296325: Investigate Page namespace 1.5x/2x image without zooming in is where using currentSrc (rather than src) was proposed, for srcset/HiDPI correctness — the reading of currentSrc is right, it is the timing that is wrong.
Suggested fix
In OpenSeadragonController.prototype.initialize (or its caller): if !this.img.complete || !this.img.currentSrc, defer initialization to a one-shot load/error listener on the image instead of proceeding. The public forceInitialize() method already exists and re-reads currentSrc, so the listener body can simply call it.