From 85824e217f13a7e86def63c09505d6e04cdbd358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Mon, 17 Feb 2025 08:31:53 +0100 Subject: [PATCH] scroll: fix position saving #1014 throttling wasn't working at all, should be debounce to get the last position --- layouts/partials/version.txt | 2 +- static/js/theme.js | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/layouts/partials/version.txt b/layouts/partials/version.txt index 44b00a1cba..61d0c1afa6 100644 --- a/layouts/partials/version.txt +++ b/layouts/partials/version.txt @@ -1 +1 @@ -7.3.2+de59e6700a230cecc75cebb1b225fe189f0189e7 \ No newline at end of file +7.3.2+0dd98363fbc04746c77cd13539a0d1b3f1a9de8e \ No newline at end of file diff --git a/static/js/theme.js b/static/js/theme.js index 1532f9c6c6..b8baa6c8ed 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -62,14 +62,11 @@ function adjustContentWidth() { elc.style[dir_padding_end] = '' + end + 'px'; } -function throttle(func, limit) { - let inThrottle; +let debounceTimeout; +function debounce(func, delay) { return function (...args) { - if (!inThrottle) { - func.apply(this, args); - inThrottle = true; - setTimeout(() => (inThrottle = false), limit); - } + clearTimeout(debounceTimeout); + debounceTimeout = setTimeout(() => func.apply(this, args), delay); }; } @@ -1327,6 +1324,7 @@ function initScrollPositionSaver() { function savePosition(event) { // #959 if we fiddle around with the history during print preview // GC will close the preview immediatley + console.log('savePosition', event); if (isPrintPreview) { return; } @@ -1341,7 +1339,7 @@ function initScrollPositionSaver() { if (!ticking) { window.requestAnimationFrame(function () { // #996 GC is so damn slow that we need further throttling - throttle(savePosition, 250); + debounce(savePosition, 200)(); ticking = false; }); ticking = true;