fix: 修复接口重复调用 — StrictMode 清理 + useModelList 去重

AppProvider useEffect 增加 aborted 标志,防止 React StrictMode
挂载→卸载→重新挂载时 refreshToken/getUserInfo 各调两次。

useModelList 提升到 LeftPanel 单例调用,通过 props 分发给
ModelSelector 和 TaskHistory,消除 /api/v1/models 重复请求。

DevTools 中显示「已停止」的请求即 StrictMode 第一轮挂载被丢弃的请求。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-09 19:24:34 +08:00
parent d95d155ab5
commit 848fdeca3d
7 changed files with 58 additions and 11 deletions

View File

@@ -17,7 +17,8 @@ import type { ColumnsType, TableProps } from 'antd/es/table';
import type { FilterValue, SorterResult } from 'antd/es/table/interface';
import { HistoryOutlined, SearchOutlined, SettingOutlined } from '@ant-design/icons';
import { useTaskList, useModelList } from '@/hooks/use-api';
import { useTaskList } from '@/hooks/use-api';
import type { ModelsListResponseBody } from '@/services/modules/models';
import { useAppContext } from '@/components/AppProvider';
import { useHomeContext } from '@/pages/home/HomeContent';
import { useTheme } from '@/components/ThemeProvider';
@@ -135,7 +136,12 @@ function pickMany(filters: TableFilters, key: string): string[] | undefined {
// ---------- 组件 ----------
export function TaskHistory() {
interface TaskHistoryProps {
/** 模型全量数据,由父组件 LeftPanel 传入(避免兄弟组件各自请求) */
allModels: ModelsListResponseBody[] | null;
}
export function TaskHistory({ allModels }: TaskHistoryProps) {
const { token } = antTheme.useToken();
const { edition } = useAppContext();
const {
@@ -210,10 +216,8 @@ export function TaskHistory() {
}));
}, [taskPage, taskPageSize]);
// -------- 模型列表(用于模型列筛选选项 + 模型名→ID 映射)--------
// -------- 模型列表(用于模型列筛选选项 + 模型名→ID 映射,由父组件传入--------
const { data: allModels } = useModelList();
const modelFilters:{text:string, value:string}[] = useMemo(() => {
if (!allModels) return [];
return allModels.map((m) => ({ text: m.name, value: m.id }));