diff --git a/src/app/(app)/ai/page.tsx b/src/app/(app)/ai/page.tsx index e639655..d19370b 100644 --- a/src/app/(app)/ai/page.tsx +++ b/src/app/(app)/ai/page.tsx @@ -51,8 +51,12 @@ export default function AIChatPage() { }); const data = await res.json(); if (data.session) { - setSessions([data.session, ...sessions]); - setCurrentSessionId(data.session.id); + // POST /api/chat returns a session without a `messages` field — normalize it + // to an empty array so the render path (currentSession.messages.length) never + // hits `undefined.length`, which crashed the page on the first new chat. + const newSession = { ...data.session, messages: [] }; + setSessions([newSession, ...sessions]); + setCurrentSessionId(newSession.id); setSidebarOpen(false); } } catch (err) { @@ -150,7 +154,7 @@ export default function AIChatPage() { }; return ( -
Tap ☰ to see past chats, or just type below to start
Type a question below to get started