From dac18b5861865b771174c8f22efd0fa29671f07b Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Thu, 25 Sep 2025 16:06:28 -0600 Subject: [PATCH] kill electric when finished streams --- apps/web/src/api/buster-electric/chats/hook.ts | 3 ++- .../web/src/api/buster-electric/messages/hooks.ts | 3 ++- .../features/chat/threeDotMenuHooks.tsx | 15 +++++++++++---- .../ChatLayoutContext/useChatStreaming.tsx | 1 - 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/web/src/api/buster-electric/chats/hook.ts b/apps/web/src/api/buster-electric/chats/hook.ts index 78f6906fd..d6ba6dfc9 100644 --- a/apps/web/src/api/buster-electric/chats/hook.ts +++ b/apps/web/src/api/buster-electric/chats/hook.ts @@ -13,6 +13,7 @@ const updateOperations: Array<`insert` | `update` | `delete`> = ['update']; export const useTrackAndUpdateChatChanges = ( { chatId, + isStreamingMessage, }: { chatId: string | undefined; isStreamingMessage: boolean; @@ -23,7 +24,7 @@ export const useTrackAndUpdateChatChanges = ( const shape = useMemo(() => { return chatShape({ chatId: chatId || '' }); }, [chatId]); - const subscribe = !!chatId; + const subscribe = !!chatId && isStreamingMessage; return useShapeStream( shape, diff --git a/apps/web/src/api/buster-electric/messages/hooks.ts b/apps/web/src/api/buster-electric/messages/hooks.ts index fab739c79..23c3541bb 100644 --- a/apps/web/src/api/buster-electric/messages/hooks.ts +++ b/apps/web/src/api/buster-electric/messages/hooks.ts @@ -33,6 +33,7 @@ export const useTrackAndUpdateMessageChanges = ( { chatId, messageId, + isStreamingMessage, }: { chatId: string | undefined; messageId: string; @@ -45,7 +46,7 @@ export const useTrackAndUpdateMessageChanges = ( const getChatMemoized = useGetChatMemoized(); const queryClient = useQueryClient(); - const subscribe = !!chatId && !!messageId && messageId !== 'undefined'; + const subscribe = !!chatId && !!messageId && messageId !== 'undefined' && isStreamingMessage; const shape = useMemo(() => { return messageShape({ chatId: chatId || '', messageId }); diff --git a/apps/web/src/components/features/chat/threeDotMenuHooks.tsx b/apps/web/src/components/features/chat/threeDotMenuHooks.tsx index e507d0081..e8d6e032d 100644 --- a/apps/web/src/components/features/chat/threeDotMenuHooks.tsx +++ b/apps/web/src/components/features/chat/threeDotMenuHooks.tsx @@ -7,6 +7,7 @@ import { createDropdownItem } from '@/components/ui/dropdown'; import { ArrowRight, DuplicatePlus, Pencil, ShareRight, Star, Trash } from '@/components/ui/icons'; import { Star as StarFilled } from '@/components/ui/icons/NucleoIconFilled'; import { useBusterNotifications } from '@/context/BusterNotifications'; +import { ensureElementExists } from '@/lib/element'; import { getIsEffectiveOwner } from '@/lib/share'; import { timeout } from '@/lib/timeout'; import { getShareAssetConfig, ShareMenuContent } from '../ShareMenu'; @@ -45,12 +46,18 @@ export const useRenameChatTitle = () => { label: 'Rename', value: 'edit-chat-title', icon: , - onClick: async () => { - const input = document.getElementById(CHAT_HEADER_TITLE_ID) as HTMLInputElement; + onClick: async (e) => { + e.stopPropagation(); + e.preventDefault(); + const input = await ensureElementExists( + () => document.getElementById(CHAT_HEADER_TITLE_ID) as HTMLInputElement + ); if (input) { - await timeout(25); + // Focus first, then select after a small delay to ensure focus completes input.focus(); - input.select(); + setTimeout(() => { + input.select(); //i think this is related to how the dropdown is closing and taking away focus + }, 200); } }, }), diff --git a/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useChatStreaming.tsx b/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useChatStreaming.tsx index 45f07a646..2093bb69a 100644 --- a/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useChatStreaming.tsx +++ b/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useChatStreaming.tsx @@ -11,7 +11,6 @@ import { import { chatQueryKeys } from '@/api/query_keys/chat'; import { metricsQueryKeys } from '@/api/query_keys/metric'; import { useBlackboxMessage } from '@/context/BlackBox/useBlackboxMessage'; -import { updateDocumentTitle } from '@/hooks/useDocumentTitle'; import { useMemoizedFn } from '@/hooks/useMemoizedFn'; import { updateChatToIChat } from '@/lib/chat';