Skip to content

Commit d3c0f28

Browse files
committed
Delay initialization of searching, in the viewer, until the first page has rendered
When searching occurs for the first time in a document, the `textContent` of all pages will be fetched from the API. If there's a pending search operation when the document loads that will thus lead to a lot of `getTextContent` calls very early on, which may unnecessarily delay rendering of the first page. Generally, in the viewer, a number of non-essential API calls[1] will be deferred until the first page has been rendered, and there's no good reason as far as I can tell to handle searching differently. --- [1] Such as e.g. `getOutline` and `getAttachments`.
1 parent d66d273 commit d3c0f28

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

web/base_viewer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ class BaseViewer {
443443
// starts to create the correct size canvas. Wait until one page is
444444
// rendered so we don't tie up too many resources early on.
445445
onePageRenderedCapability.promise.then(() => {
446+
if (this.findController) {
447+
this.findController.setDocument(pdfDocument); // Enable searching.
448+
}
449+
446450
if (pdfDocument.loadingParams['disableAutoFetch']) {
447451
// XXX: Printing is semi-broken with auto fetch disabled.
448452
pagesCapability.resolve();
@@ -471,9 +475,6 @@ class BaseViewer {
471475

472476
this.eventBus.dispatch('pagesinit', { source: this, });
473477

474-
if (this.findController) {
475-
this.findController.setDocument(pdfDocument); // Enable searching.
476-
}
477478
if (this.defaultRenderingQueue) {
478479
this.update();
479480
}

0 commit comments

Comments
 (0)