diff --git a/packages/bolt/app/components/chat/Chat.client.tsx b/packages/bolt/app/components/chat/Chat.client.tsx index 42ff709..e5400f9 100644 --- a/packages/bolt/app/components/chat/Chat.client.tsx +++ b/packages/bolt/app/components/chat/Chat.client.tsx @@ -63,7 +63,10 @@ export function ChatImpl({ initialMessages, storeMessageHistory }: ChatProps) { useEffect(() => { parseMessages(messages, isLoading); - storeMessageHistory(messages).catch((error) => toast.error(error.message)); + + if (messages.length > initialMessages.length) { + storeMessageHistory(messages).catch((error) => toast.error(error.message)); + } }, [messages, isLoading, parseMessages]); const scrollTextArea = () => { diff --git a/packages/bolt/app/lib/persistence/useChatHistory.ts b/packages/bolt/app/lib/persistence/useChatHistory.ts index cd6895f..526e1a6 100644 --- a/packages/bolt/app/lib/persistence/useChatHistory.ts +++ b/packages/bolt/app/lib/persistence/useChatHistory.ts @@ -14,12 +14,13 @@ export interface ChatHistory { const persistenceEnabled = !import.meta.env.VITE_DISABLE_PERSISTENCE; -const db = persistenceEnabled ? await openDatabase() : undefined; +export const db = persistenceEnabled ? await openDatabase() : undefined; export function useChatHistory() { const navigate = useNavigate(); - const { id: chatId } = useLoaderData<{ id?: string }>(); + const { id: mixedId } = useLoaderData<{ id?: string }>(); + const [chatId, setChatId] = useState(mixedId); const [initialMessages, setInitialMessages] = useState([]); const [ready, setReady] = useState(false); const [entryId, setEntryId] = useState(); @@ -42,6 +43,9 @@ export function useChatHistory() { .then((storedMessages) => { if (storedMessages && storedMessages.messages.length > 0) { setInitialMessages(storedMessages.messages); + setUrlId(storedMessages.urlId); + setDescription(storedMessages.description); + setChatId(storedMessages.id); } else { navigate(`/`, { replace: true }); }