Fix AI chat: input blocked by bottom nav + first-chat crash
- Add pb-16 to /ai root so the input clears the fixed BottomNav (only page using h-screen instead of min-h-screen+pb-24). - Normalize new sessions with messages:[] in createNewSession so render no longer hits undefined.length and crashes on first chat. - Make render defensive (messages?.length ?? 0). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
dad0611350
commit
2b534d4c43
1 changed files with 9 additions and 5 deletions
|
|
@ -51,8 +51,12 @@ export default function AIChatPage() {
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.session) {
|
if (data.session) {
|
||||||
setSessions([data.session, ...sessions]);
|
// POST /api/chat returns a session without a `messages` field — normalize it
|
||||||
setCurrentSessionId(data.session.id);
|
// 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);
|
setSidebarOpen(false);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -150,7 +154,7 @@ export default function AIChatPage() {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen bg-gradient-to-br from-rose-50 to-amber-50 dark:from-gray-900 dark:to-gray-800 overflow-hidden">
|
<div className="flex h-screen pb-16 bg-gradient-to-br from-rose-50 to-amber-50 dark:from-gray-900 dark:to-gray-800 overflow-hidden">
|
||||||
|
|
||||||
{/* Sidebar overlay on mobile */}
|
{/* Sidebar overlay on mobile */}
|
||||||
{sidebarOpen && (
|
{sidebarOpen && (
|
||||||
|
|
@ -227,12 +231,12 @@ export default function AIChatPage() {
|
||||||
<p className="text-sm text-gray-400 dark:text-gray-500">Tap ☰ to see past chats, or just type below to start</p>
|
<p className="text-sm text-gray-400 dark:text-gray-500">Tap ☰ to see past chats, or just type below to start</p>
|
||||||
<Button onClick={createNewSession} className="mt-2 rounded-full">New Chat</Button>
|
<Button onClick={createNewSession} className="mt-2 rounded-full">New Chat</Button>
|
||||||
</div>
|
</div>
|
||||||
) : currentSession.messages.length === 0 ? (
|
) : (currentSession.messages?.length ?? 0) === 0 ? (
|
||||||
<div className="h-full flex flex-col items-center justify-center text-center gap-2">
|
<div className="h-full flex flex-col items-center justify-center text-center gap-2">
|
||||||
<p className="text-gray-400 dark:text-gray-500 text-sm">Type a question below to get started</p>
|
<p className="text-gray-400 dark:text-gray-500 text-sm">Type a question below to get started</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
currentSession.messages.map((msg, i) => (
|
(currentSession.messages ?? []).map((msg, i) => (
|
||||||
<div
|
<div
|
||||||
key={i}
|
key={i}
|
||||||
className={`flex ${msg.role === "user" ? "justify-end" : "justify-start"}`}
|
className={`flex ${msg.role === "user" ? "justify-end" : "justify-start"}`}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue