From 9301c44d3f5c87fd7f1aae255acefc793696599f Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Sun, 8 Feb 2026 16:17:51 -0800 Subject: [PATCH] fix(AI Assistant): chat suggestion performance improvements --- admin/inertia/components/chat/index.tsx | 13 +++++++++---- admin/inertia/lib/api.ts | 5 +++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/admin/inertia/components/chat/index.tsx b/admin/inertia/components/chat/index.tsx index 96f5f36..8359d2c 100644 --- a/admin/inertia/components/chat/index.tsx +++ b/admin/inertia/components/chat/index.tsx @@ -55,11 +55,13 @@ export default function Chat({ const { data: chatSuggestions, isLoading: chatSuggestionsLoading } = useQuery({ queryKey: ['chatSuggestions'], - queryFn: async () => { - const res = await api.getChatSuggestions() + queryFn: async ({ signal }) => { + const res = await api.getChatSuggestions(signal) return res ?? [] }, - enabled: suggestionsEnabled, + enabled: suggestionsEnabled && !activeSessionId, + refetchOnWindowFocus: false, + refetchOnMount: false, }) const deleteAllSessionsMutation = useMutation({ @@ -151,6 +153,9 @@ export default function Chat({ const handleSessionSelect = useCallback( async (sessionId: string) => { + // Cancel any ongoing suggestions fetch + queryClient.cancelQueries({ queryKey: ['chatSuggestions'] }) + setActiveSessionId(sessionId) // Load messages for this session const sessionData = await api.getChatSession(sessionId) @@ -172,7 +177,7 @@ export default function Chat({ setSelectedModel(sessionData.model) } }, - [installedModels] + [installedModels, queryClient] ) const handleSendMessage = useCallback( diff --git a/admin/inertia/lib/api.ts b/admin/inertia/lib/api.ts index 0df5ac0..b50e0e2 100644 --- a/admin/inertia/lib/api.ts +++ b/admin/inertia/lib/api.ts @@ -147,10 +147,11 @@ class API { })() } - async getChatSuggestions() { + async getChatSuggestions(signal?: AbortSignal) { return catchInternal(async () => { const response = await this.client.get<{ suggestions: string[] }>( - '/chat/suggestions' + '/chat/suggestions', + { signal } ) return response.data.suggestions })()