Abort various timeouts, in PDFViewer, when closing the document (PR 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
```
This commit is contained in:
Jonas Jenwald 2025-02-25 13:04:07 +01:00
parent aa70b28365
commit 71ad9fd0b7

View File

@ -1173,6 +1173,7 @@ class PDFViewer {
this.#hiddenCopyElement?.remove(); this.#hiddenCopyElement?.remove();
this.#hiddenCopyElement = null; this.#hiddenCopyElement = null;
this.#cleanupTimeouts();
this.#cleanupSwitchAnnotationEditorMode(); this.#cleanupSwitchAnnotationEditorMode();
} }
@ -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() { #cleanupSwitchAnnotationEditorMode() {
this.#switchAnnotationEditorModeAC?.abort(); this.#switchAnnotationEditorModeAC?.abort();
this.#switchAnnotationEditorModeAC = null; this.#switchAnnotationEditorModeAC = null;
@ -2466,14 +2478,8 @@ class PDFViewer {
for (const pageView of this._pages) { for (const pageView of this._pages) {
pageView.update(updateArgs); pageView.update(updateArgs);
} }
if (this.#scaleTimeoutId !== null) { this.#cleanupTimeouts();
clearTimeout(this.#scaleTimeoutId);
this.#scaleTimeoutId = null;
}
if (this.#scrollTimeoutId !== null) {
clearTimeout(this.#scrollTimeoutId);
this.#scrollTimeoutId = null;
}
if (!noUpdate) { if (!noUpdate) {
this.update(); this.update();
} }