fix(login): 翻页请求不再被轮询吞掉
loadTasks 原来用「有请求在跑就直接返回」防重入,加了分页后这会把用户点 翻页/改筛选时发出的请求一并丢掉:页面停在上一页,要等下一次轮询(3~15s) 才会更新。改为请求序号「最新请求获胜」:过期响应直接丢弃,不再丢请求。
This commit is contained in:
@@ -78,7 +78,8 @@ export default function LoginTasksPage() {
|
||||
return localStorage.getItem('login_api_strategy') || 'wgapi';
|
||||
});
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
const tasksLoadingRef = useRef(false);
|
||||
// 任务列表请求序号:保证「最新一次请求」的结果才落到界面上。
|
||||
const taskRequestRef = useRef(0);
|
||||
const accountPageRequestRef = useRef(0);
|
||||
const tagSelectionRequestRef = useRef(0);
|
||||
const [tagAccountIds, setTagAccountIds] = useState<Record<string, number[]>>({});
|
||||
@@ -206,8 +207,9 @@ export default function LoginTasksPage() {
|
||||
}, [loadAllAccountsByTag, selectedTags]);
|
||||
|
||||
const loadTasks = useCallback(async () => {
|
||||
if (tasksLoadingRef.current) return;
|
||||
tasksLoadingRef.current = true;
|
||||
// 「最新请求获胜」而不是「有请求在跑就丢弃」:轮询请求在途时用户点了翻页,
|
||||
// 旧写法会把这次翻页请求直接吞掉,页面停在上一页直到下次轮询。
|
||||
const reqId = ++taskRequestRef.current;
|
||||
try {
|
||||
const data = await loginApi.listTasksPaged({
|
||||
page: taskPage,
|
||||
@@ -215,12 +217,11 @@ export default function LoginTasksPage() {
|
||||
batch_id: batchId || undefined,
|
||||
status: taskStatus || undefined,
|
||||
});
|
||||
if (reqId !== taskRequestRef.current) return; // 已有更新的请求,丢弃本次结果
|
||||
setTasks(data.items);
|
||||
setTaskTotal(data.total);
|
||||
} catch {
|
||||
// 忽略轮询失败,下一次定时刷新会继续尝试。
|
||||
} finally {
|
||||
tasksLoadingRef.current = false;
|
||||
}
|
||||
}, [batchId, taskPage, taskPageSize, taskStatus]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user