From ab000bcd410b7fad8329870c4fab6929968574e0 Mon Sep 17 00:00:00 2001 From: Yuyao Huang Date: Sat, 9 May 2026 15:59:13 +0800 Subject: [PATCH] fix: delay scroll handler binding to skip queued scroll event scrollTop assignment triggers an async scroll event. When all tasks fit in the viewport, handleScrollFocus recalculates center-aligned task and picks the last one instead of the saved one. Using setTimeout(0) defers handler binding to after the queued event fires. --- static/js/tasks.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/static/js/tasks.js b/static/js/tasks.js index 20ed1c2..b910252 100644 --- a/static/js/tasks.js +++ b/static/js/tasks.js @@ -170,8 +170,12 @@ function initScrollFocus() { scrollView.removeEventListener("scroll", handleScrollFocus); scrollView.removeEventListener("scroll", handleScrollSave); - scrollView.addEventListener("scroll", handleScrollFocus); - scrollView.addEventListener("scroll", handleScrollSave); + + // Delay binding to skip the async scroll event queued by scrollToTask + setTimeout(() => { + scrollView.addEventListener("scroll", handleScrollFocus); + scrollView.addEventListener("scroll", handleScrollSave); + }, 0); } function handleScrollFocus() {