fix: prevent scroll position override during page initialization

Add isInitializing flag to block persistSelectedTask during loadTasks,
preventing handleScrollFocus from overwriting the saved scroll position
This commit is contained in:
Yuyao Huang 2026-05-09 14:05:11 +08:00
parent f021395773
commit 27f85cd913

View File

@ -5,6 +5,7 @@ let selectedTaskId = null;
let sortableInstance = null;
let persistTimer = null;
let currentUser = null;
let isInitializing = false;
async function loadGoals() {
try {
@ -37,6 +38,7 @@ async function loadGoals() {
async function loadTasks() {
if (!selectedGoalId) return;
isInitializing = true;
try {
tasks = await get(`/api/tasks?goal_id=${selectedGoalId}`);
@ -67,11 +69,13 @@ async function loadTasks() {
initScrollFocus();
} catch (error) {
console.error("Failed to load tasks:", error);
} finally {
isInitializing = false;
}
}
async function persistSelectedTask(taskId) {
if (!selectedGoalId) return;
if (!selectedGoalId || isInitializing) return;
try {
await patch(`/api/goals/${selectedGoalId}/selected-task`, { task_id: taskId });
const goal = goals.find(g => g.id === selectedGoalId);