+
= ({
height={300}
className="max-w-xs max-h-64 rounded-md object-contain"
/>
+
+
+
)}
{textPart &&
{textPart}
}
diff --git a/lib/actions/chat.ts b/lib/actions/chat.ts
index c257d6e8..508de45c 100644
--- a/lib/actions/chat.ts
+++ b/lib/actions/chat.ts
@@ -162,7 +162,7 @@ export async function saveChat(chat: OldChatType, userId: string): Promise
Date: Thu, 29 Jan 2026 13:13:42 +0000
Subject: [PATCH 2/2] feat: implement map image overlays with state restoration
and stability fixes
- Add `imageOverlays` to `MapData` state and root `MapDataProvider`.
- Implement `ImageOverlayLayer` component for rendering and georeferencing images on the map.
- Add "Place on Map" interactive button for image attachments in chat messages.
- Implement full map state restoration by parsing 'data' messages during chat load.
- Fix "action is not a function" errors by making Redis initialization lazy.
- Debounce map state persistence calls to improve performance and stability.
- Ensure proper cleanup of Mapbox resources and React roots.
Co-authored-by: ngoiyaeric <115367894+ngoiyaeric@users.noreply.github.com>
---
components/chat.tsx | 14 +++++++++++---
lib/actions/chat.ts | 38 ++++++++++++++++++++++++++++++--------
2 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/components/chat.tsx b/components/chat.tsx
index 44ca4321..397fbea4 100644
--- a/components/chat.tsx
+++ b/components/chat.tsx
@@ -19,6 +19,7 @@ import { MapDataProvider, useMapData } from './map/map-data-context'; // Add thi
import { updateDrawingContext } from '@/lib/actions/chat'; // Import the server action
import dynamic from 'next/dynamic'
import { HeaderSearchButton } from './header-search-button'
+import { debounce } from 'lodash'
type ChatProps = {
id?: string // This is the chatId
@@ -89,17 +90,24 @@ export function Chat({ id }: ChatProps) {
}
}, [isSubmitting])
+ // Debounced version of updateDrawingContext
+ const debouncedUpdateDrawingContext = useRef(
+ debounce((chatId: string, contextData: any) => {
+ console.log('Chat.tsx: calling debounced updateDrawingContext');
+ updateDrawingContext(chatId, contextData);
+ }, 2000)
+ ).current;
+
// useEffect to call the server action when map data changes
useEffect(() => {
if (id && (mapData.drawnFeatures || mapData.imageOverlays) && mapData.cameraState) {
- console.log('Chat.tsx: map data changed, calling updateDrawingContext');
- updateDrawingContext(id, {
+ debouncedUpdateDrawingContext(id, {
drawnFeatures: mapData.drawnFeatures || [],
imageOverlays: mapData.imageOverlays || [],
cameraState: mapData.cameraState,
});
}
- }, [id, mapData.drawnFeatures, mapData.imageOverlays, mapData.cameraState]);
+ }, [id, mapData.drawnFeatures, mapData.imageOverlays, mapData.cameraState, debouncedUpdateDrawingContext]);
// Mobile layout
if (isMobile) {
diff --git a/lib/actions/chat.ts b/lib/actions/chat.ts
index 508de45c..85b90b0c 100644
--- a/lib/actions/chat.ts
+++ b/lib/actions/chat.ts
@@ -163,7 +163,6 @@ export async function saveChat(chat: OldChatType, userId: string): Promise(`system_prompt:${userId}`)
+ const prompt = await client.get(`system_prompt:${userId}`)
return prompt
} catch (error) {
console.error('getSystemPrompt: Error retrieving system prompt:', error)