diff --git a/frontend/src/components/UnifiedChat.tsx b/frontend/src/components/UnifiedChat.tsx index 052dc5206..d1ce813dc 100644 --- a/frontend/src/components/UnifiedChat.tsx +++ b/frontend/src/components/UnifiedChat.tsx @@ -963,6 +963,7 @@ export function UnifiedChat() { const assistantStreamingRef = useRef(false); const abortControllerRef = useRef(null); + const billingRefreshTimeoutRef = useRef | null>(null); const fileInputRef = useRef(null); const documentInputRef = useRef(null); @@ -992,6 +993,15 @@ export function UnifiedChat() { } }, [input]); + // Cleanup billing refresh timeout on unmount + useEffect(() => { + return () => { + if (billingRefreshTimeoutRef.current) { + clearTimeout(billingRefreshTimeoutRef.current); + } + }; + }, []); + // Auto-focus textbox on desktop (not mobile to avoid keyboard popup interrupting reading) // Focus when: app launches, new chat, conversation loads, or assistant finishes streaming useEffect(() => { @@ -2365,6 +2375,12 @@ export function UnifiedChat() { // Re-enable polling after streaming completes assistantStreamingRef.current = false; setCurrentResponseId(undefined); + + // Invalidate billing status after a delay to allow backend processing + billingRefreshTimeoutRef.current = setTimeout(() => { + queryClient.invalidateQueries({ queryKey: ["billingStatus"] }); + billingRefreshTimeoutRef.current = null; + }, 3000); } } catch (error) { console.error("Failed to send message:", error);