From 95a4fa25b9048c05e87f5906289e4b6920b233e3 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 26 Jun 2018 14:08:04 +0200 Subject: [PATCH] Don't wait arbitrary long for all pages to be resolved before attempting to re-apply the initial position on load (PR 6318 follow-up) With the current code, the location in the viewer could change *well* after the user has started to interact with the viewer (for very large and/or slow loading documents). Attempt to reduce the likelyhood of that happening, by adding an upper bound to the time spent waiting before attempting to re-apply the initial position. --- web/app.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/web/app.js b/web/app.js index 8025431b2..e4f01cf15 100644 --- a/web/app.js +++ b/web/app.js @@ -48,7 +48,8 @@ import { Toolbar } from './toolbar'; import { ViewHistory } from './view_history'; const DEFAULT_SCALE_DELTA = 1.1; -const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; +const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; // ms +const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms const DefaultExternalServices = { updateFindControlState(data) {}, @@ -1074,10 +1075,20 @@ let PDFViewerApplication = { if (!this.isViewerEmbedded) { pdfViewer.focus(); } - return pagesPromise; + + return Promise.race([ + pagesPromise, + new Promise((resolve) => { + setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT); + }), + ]); }).then(() => { // For documents with different page sizes, once all pages are resolved, // ensure that the correct location becomes visible on load. + // To reduce the risk, in very large and/or slow loading documents, + // that the location changes *after* the user has started interacting + // with the viewer, wait for either `pagesPromise` or a timeout above. + if (!initialParams.bookmark && !initialParams.hash) { return; }