From dc71bedac1e102f670b3c6e7ec6a6362513ea9b7 Mon Sep 17 00:00:00 2001 From: Mingze Date: Fri, 13 Dec 2019 14:19:46 -0800 Subject: [PATCH] fix(test): Fix possible sanity test bug (#1117) --- src/lib/ThumbnailsSidebar.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/ThumbnailsSidebar.js b/src/lib/ThumbnailsSidebar.js index 45874f91c..1d30319b3 100644 --- a/src/lib/ThumbnailsSidebar.js +++ b/src/lib/ThumbnailsSidebar.js @@ -39,6 +39,9 @@ class ThumbnailsSidebar { /** @property {Object} - Cache for the thumbnail image elements */ thumbnailImageCache; + /** @property {Array} - The ID values returned by the call to window.requestAnimationFrame() */ + animationFrameRequestIds; + /** * [constructor] * @@ -46,6 +49,7 @@ class ThumbnailsSidebar { * @param {PDFViewer} pdfViewer - the PDFJS viewer */ constructor(element, pdfViewer) { + this.animationFrameRequestIds = []; this.anchorEl = element; this.currentThumbnails = []; this.pdfViewer = pdfViewer; @@ -132,6 +136,10 @@ class ThumbnailsSidebar { * @return {void} */ destroy() { + if (this.animationFrameRequestIds.length > 0) { + this.animationFrameRequestIds.forEach(id => cancelAnimationFrame(id)); + } + if (this.virtualScroller) { this.virtualScroller.destroy(); this.virtualScroller = null; @@ -289,7 +297,8 @@ class ThumbnailsSidebar { * @return {void} */ requestThumbnailImage(itemIndex, thumbnailEl) { - requestAnimationFrame(() => { + const requestId = requestAnimationFrame(() => { + this.animationFrameRequestIds = this.animationFrameRequestIds.filter(id => id !== requestId); this.createThumbnailImage(itemIndex).then(imageEl => { // Promise will resolve with null if create image request was already in progress if (imageEl) { @@ -302,6 +311,8 @@ class ThumbnailsSidebar { this.renderNextThumbnailImage(); }); }); + + this.animationFrameRequestIds.push(requestId); } /**