Skip to content

Commit

Permalink
Abort various timeouts, in PDFViewer, when closing the document (PR…
Browse files Browse the repository at this point in the history
… 19128 follow-up)

Looking at recent integration-test logs there's occasionally warnings about trying to invoke `PDFViewer.prototype.update` too late, which probably started with PR 19128 (see log excerpt below).
Given that we already had another timeout before that PR the problem was pre-existing, but it seems to trigger more easily now.

```
JavaScript warning: http://127.0.0.1:42333/build/generic/web/viewer.mjs, line 12668: Script terminated by timeout at:
update@http://127.0.0.1:42333/build/generic/web/viewer.mjs:12668:9
@http://127.0.0.1:42333/build/generic/web/viewer.mjs:12373:12
setTimeout handler*_scrollUpdate@http://127.0.0.1:42333/build/generic/web/viewer.mjs:12371:29
viewAreaElementScrolled@http://127.0.0.1:42333/build/generic/web/viewer.mjs:154:15
FrameRequestCallback*debounceScroll@http://127.0.0.1:42333/build/generic/web/viewer.mjs:140:18
EventListener.handleEvent*watchScroll@http://127.0.0.1:42333/build/generic/web/viewer.mjs:165:19
PDFViewer@http://127.0.0.1:42333/build/generic/web/viewer.mjs:11777:19
_initializeViewerComponents@http://127.0.0.1:42333/build/generic/web/viewer.mjs:15081:23
initialize@http://127.0.0.1:42333/build/generic/web/viewer.mjs:14931:16
async*run@http://127.0.0.1:42333/build/generic/web/viewer.mjs:15227:16
webViewerLoad@http://127.0.0.1:42333/build/generic/web/viewer.mjs:17078:24
@http://127.0.0.1:42333/build/generic/web/viewer.mjs:17082:3
```
  • Loading branch information
Snuffleupagus committed Feb 25, 2025
1 parent aa70b28 commit 71ad9fd
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions web/pdf_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,7 @@ class PDFViewer {
this.#hiddenCopyElement?.remove();
this.#hiddenCopyElement = null;

this.#cleanupTimeouts();
this.#cleanupSwitchAnnotationEditorMode();
}

Expand Down Expand Up @@ -2340,6 +2341,17 @@ class PDFViewer {
]);
}

#cleanupTimeouts() {
if (this.#scaleTimeoutId !== null) {
clearTimeout(this.#scaleTimeoutId);
this.#scaleTimeoutId = null;
}
if (this.#scrollTimeoutId !== null) {
clearTimeout(this.#scrollTimeoutId);
this.#scrollTimeoutId = null;
}
}

#cleanupSwitchAnnotationEditorMode() {
this.#switchAnnotationEditorModeAC?.abort();
this.#switchAnnotationEditorModeAC = null;
Expand Down Expand Up @@ -2466,14 +2478,8 @@ class PDFViewer {
for (const pageView of this._pages) {
pageView.update(updateArgs);
}
if (this.#scaleTimeoutId !== null) {
clearTimeout(this.#scaleTimeoutId);
this.#scaleTimeoutId = null;
}
if (this.#scrollTimeoutId !== null) {
clearTimeout(this.#scrollTimeoutId);
this.#scrollTimeoutId = null;
}
this.#cleanupTimeouts();

if (!noUpdate) {
this.update();
}
Expand Down

0 comments on commit 71ad9fd

Please sign in to comment.