Disconnect the resize observer and remove scroll listener when unbinding window events

This commit is contained in:
Calixte Denizet 2024-05-30 18:53:07 +02:00
parent fdb3617e0f
commit 4430b6b703
4 changed files with 35 additions and 4 deletions

View file

@ -155,7 +155,7 @@ function scrollIntoView(element, spot, scrollMatches = false) {
* Helper function to start monitoring the scroll event and converting them into
* PDF.js friendly one: with scroll debounce and scroll direction.
*/
function watchScroll(viewAreaElement, callback) {
function watchScroll(viewAreaElement, callback, abortSignal = undefined) {
const debounceScroll = function (evt) {
if (rAF) {
return;
@ -189,7 +189,10 @@ function watchScroll(viewAreaElement, callback) {
};
let rAF = null;
viewAreaElement.addEventListener("scroll", debounceScroll, true);
viewAreaElement.addEventListener("scroll", debounceScroll, {
useCapture: true,
signal: abortSignal,
});
return state;
}