From 3c00317aeb0b62269644b8c144696a0a3b70bd6c Mon Sep 17 00:00:00 2001 From: jialin Date: Tue, 14 Jul 2026 20:22:28 +0800 Subject: [PATCH] fix(models): cancel model-route-targets watch on inactive tab --- src/hooks/use-watch-list.ts | 10 ++++++++-- src/pages/llmodels/components/table-list.tsx | 7 +++---- src/pages/llmodels/deployments.tsx | 10 ++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/hooks/use-watch-list.ts b/src/hooks/use-watch-list.ts index 895adbee..83e7a926 100644 --- a/src/hooks/use-watch-list.ts +++ b/src/hooks/use-watch-list.ts @@ -40,6 +40,11 @@ export default function useWatchList>(API: string) { } }); + const cancelWatch = useMemoizedFn(() => { + chunkRequestRef.current?.current?.cancel?.(); + listRequestTokenRef.current?.cancel?.(); + }); + const queryAllDataList = async ( params: Global.SearchParams, options?: any @@ -78,14 +83,15 @@ export default function useWatchList>(API: string) { useEffect(() => { createWatchChunkRequest(); return () => { - chunkRequestRef.current?.cancel?.(); - listRequestTokenRef.current?.cancel?.(); + cancelWatch(); }; }, []); return { watchDataList, setWatchDataList, + startWatch: createWatchChunkRequest, + cancelWatch, deleteItemFromCache: handleDeleteItemFromCache }; } diff --git a/src/pages/llmodels/components/table-list.tsx b/src/pages/llmodels/components/table-list.tsx index 2a0355fd..0969c40e 100644 --- a/src/pages/llmodels/components/table-list.tsx +++ b/src/pages/llmodels/components/table-list.tsx @@ -5,9 +5,7 @@ import { PageActionType } from '@/config/types'; import useBodyScroll from '@/hooks/use-body-scroll'; import useExpandedRowKeys from '@/hooks/use-expanded-row-keys'; import useTableRowSelection from '@/hooks/use-table-row-selection'; -import useWatchList from '@/hooks/use-watch-list'; import useNoResourceResult from '@/pages/llmodels/hooks/use-no-resource-result'; -import { MODEL_ROUTE_TARGETS } from '@/pages/model-routes/apis'; import { TargetStatusValueMap } from '@/pages/model-routes/config'; import useOpenPlayground from '@/pages/model-routes/hooks/use-open-playground'; import useGranfanaLink from '@/pages/resources/hooks/use-grafana-link'; @@ -92,6 +90,7 @@ interface ModelsProps { loadend: boolean; total: number; filterValues?: Record; + targetList?: any[]; } const getFormattedData = (record: any, extraData = {}) => ({ @@ -129,7 +128,8 @@ const Models: React.FC = ({ queryParams, loading, loadend, - total + total, + targetList = [] }) => { const { generateFormValues, clusterList, workerList } = useDeploymentsContext(); @@ -155,7 +155,6 @@ const Models: React.FC = ({ expandedRowKeys } = useExpandedRowKeys(expandAtom); const { handleOpenPlayGround } = useOpenPlayground(); - const { watchDataList: targetList } = useWatchList(MODEL_ROUTE_TARGETS); const { openViewLogsModal, openViewLogsModalStatus, closeViewLogsModal } = useViewInstanceLogs(); diff --git a/src/pages/llmodels/deployments.tsx b/src/pages/llmodels/deployments.tsx index 112bcdb7..0aa999a5 100644 --- a/src/pages/llmodels/deployments.tsx +++ b/src/pages/llmodels/deployments.tsx @@ -3,6 +3,8 @@ import useSetChunkRequest from '@/hooks/use-chunk-request'; import { usePaginationStatus } from '@/hooks/use-pagination-status'; import { useTableMultiSort } from '@/hooks/use-table-sort'; import useUpdateChunkedList from '@/hooks/use-update-chunk-list'; +import useWatchList from '@/hooks/use-watch-list'; +import { MODEL_ROUTE_TARGETS } from '@/pages/model-routes/apis'; import { TableOrder, TableProvider } from '@gpustack/core-ui'; import { useMemoizedFn } from 'ahooks'; import _ from 'lodash'; @@ -31,6 +33,11 @@ const Models = forwardRef((props, ref) => { const { setChunkRequest, createAxiosToken } = useSetChunkRequest(); const { setChunkRequest: setModelInstanceChunkRequest } = useSetChunkRequest(); + const { + watchDataList: targetList, + startWatch: startTargetsWatch, + cancelWatch: cancelTargetsWatch + } = useWatchList(MODEL_ROUTE_TARGETS); const [modelInstances, setModelInstances] = useState([]); const [dataSource, setDataSource] = useState<{ dataList: ListItem[]; @@ -255,6 +262,7 @@ const Models = forwardRef((props, ref) => { cacheInsDataListRef.current = []; chunkInstanceRequedtRef.current?.current?.cancel?.(); instancesToken.current?.cancel?.(); + cancelTargetsWatch(); }); const resumeRequestsOnPageActive = useMemoizedFn(async () => { @@ -265,6 +273,7 @@ const Models = forwardRef((props, ref) => { await getAllModelInstances(); await createModelsInstanceChunkRequest(); await createModelsChunkRequest(); + await startTargetsWatch(); }); const handleOnCancelViewLogs = useMemoizedFn(async () => { @@ -483,6 +492,7 @@ const Models = forwardRef((props, ref) => { total={dataSource.total} deleteIds={dataSource.deletedIds} filterValues={filterValues} + targetList={targetList} > );