From 58a27286476646ef9b2a4b10b63aea564d13a518 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 20 Nov 2021 22:31:31 +0100 Subject: [PATCH] Ensure that `BaseViewer.#ensurePdfPageLoaded` updates the `PDFLinkService`-pagesRefCache if necessary The issue that this patch fixes has existed ever since the viewer was first re-factored into components, however it only really affects the `disableAutoFetch = true` mode. By default we're fetching all pages in `BaseViewer.setDocument`, and as part of the parsing/initialization we're also populating the `PDFLinkService`-pagesRefCache. The purpose of that cache is to make navigating to any internal destinations faster, by not having to (asynchronously) lookup the pageNumber via the API when handling the destination. In comparison, when the `disableAutoFetch = true` mode is being used we're instead *lazily* initializing the pages in the `BaseViewer.#ensurePdfPageLoaded`-method. For some reason, that I can only assume is a simple oversight, we're not attempting to update the `PDFLinkService`-pagesRefCache in that case. --- web/base_viewer.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/base_viewer.js b/web/base_viewer.js index dd8084877..074447bed 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -1366,6 +1366,9 @@ class BaseViewer { if (!pageView.pdfPage) { pageView.setPdfPage(pdfPage); } + if (!this.linkService._cachedPageNumber(pdfPage.ref)) { + this.linkService.cachePageRef(pageView.id, pdfPage.ref); + } return pdfPage; } catch (reason) { console.error("Unable to get page for page view", reason);