diff --git a/chat_diff.patch b/chat_diff.patch new file mode 100644 index 00000000..3546db5e --- /dev/null +++ b/chat_diff.patch @@ -0,0 +1,27 @@ +--- components/chat.tsx ++++ components/chat.tsx +@@ -40,6 +40,7 @@ + const [isSubmitting, setIsSubmitting] = useState(false) + const [suggestions, setSuggestions] = useState(null) + const chatPanelRef = useRef(null); ++ const lastRefreshedMessageIdRef = useRef(null) + + const handleAttachment = () => { + chatPanelRef.current?.handleAttachmentClick(); +@@ -76,10 +77,15 @@ + }, [id, path, messages]) + + useEffect(() => { +- if (aiState.messages[aiState.messages.length - 1]?.type === 'response') { +- // Refresh the page to chat history updates ++ // Find the last message of type 'response' ++ const responseMessage = [...aiState.messages] ++ .reverse() ++ .find(m => m.type === 'response') ++ ++ if (responseMessage && responseMessage.id !== lastRefreshedMessageIdRef.current) { ++ // Refresh the page to update chat history in the sidebar ++ lastRefreshedMessageIdRef.current = responseMessage.id + router.refresh() + } + }, [aiState, router]) diff --git a/components/chat.tsx b/components/chat.tsx index ef47a124..15b8b3df 100644 --- a/components/chat.tsx +++ b/components/chat.tsx @@ -40,6 +40,7 @@ export function Chat({ id }: ChatProps) { const [isSubmitting, setIsSubmitting] = useState(false) const [suggestions, setSuggestions] = useState(null) const chatPanelRef = useRef(null); + const lastRefreshedMessageIdRef = useRef(null) const handleAttachment = () => { chatPanelRef.current?.handleAttachmentClick(); @@ -76,8 +77,14 @@ export function Chat({ id }: ChatProps) { }, [id, path, messages]) useEffect(() => { - if (aiState.messages[aiState.messages.length - 1]?.type === 'response') { - // Refresh the page to chat history updates + // Find the last message of type 'response' + const responseMessage = [...aiState.messages] + .reverse() + .find(m => m.type === 'response') + + if (responseMessage && responseMessage.id !== lastRefreshedMessageIdRef.current) { + // Refresh the page to update chat history in the sidebar + lastRefreshedMessageIdRef.current = responseMessage.id router.refresh() } }, [aiState, router]) @@ -106,7 +113,7 @@ export function Chat({ id }: ChatProps) { // Mobile layout if (isMobile) { return ( - {/* Add Provider */} + <>
@@ -160,13 +167,13 @@ export function Chat({ id }: ChatProps) { )}
-
+ ); } // Desktop layout return ( - {/* Add Provider */} + <>
{/* This is the new div for scrolling */} @@ -224,6 +231,6 @@ export function Chat({ id }: ChatProps) { {activeView ? : isUsageOpen ? : }
-
+ ); } diff --git a/components/graph-section.tsx b/components/graph-section.tsx index 1148bdb1..9f2e4765 100644 --- a/components/graph-section.tsx +++ b/components/graph-section.tsx @@ -29,7 +29,7 @@ import { StreamableValue, useStreamableValue } from 'ai/rsc' const COLORS = ['#0088FE', '#00C49F', '#FFBB28', '#FF8042', '#8884d8', '#82ca9d'] interface GraphSectionProps { - result: DataAnalysisResult | string | StreamableValue + result: DataAnalysisResult | string | StreamableValue | StreamableValue } export function GraphSection({ result }: GraphSectionProps) { diff --git a/components/map/mapbox-map.tsx b/components/map/mapbox-map.tsx index ef876721..eecd7f54 100644 --- a/components/map/mapbox-map.tsx +++ b/components/map/mapbox-map.tsx @@ -467,7 +467,7 @@ export const Mapbox: React.FC<{ position?: { latitude: number; longitude: number geolocationWatchIdRef.current = null } } - }, [setMap, setIsMapLoaded, captureMapCenter, handleUserInteraction, stopRotation, position?.latitude, position?.longitude, mapData.cameraState]) + }, [setMap, setIsMapLoaded, captureMapCenter, handleUserInteraction, stopRotation]) // Handle map mode changes useEffect(() => {