{messages.map((m) => (
{m.role}:{" "}
{m.parts.map((p, i) =>
p.type === "text" ? {p.text} : null,
)}
))}
);
}
```
The request body now contains only the latest message instead of the full conversation. The server pulls history from Redis and never trusts the client for older turns, which also stops a tampered client from rewriting earlier turns.
## How do you load the initial chat history on first paint?
Because we trimmed the request to just the latest message, the client starts with whatever array you pass into useChat as initial messages. In Next.js App Router, the cleanest way is to read Redis in a server component and hand the array to the chat component:
```tsx id="code-oo9rves6"
// app/chat/[id]/page.tsx
import { loadChat } from "@/util/chat-store";
import { Chat } from "@/ui/chat";
export default async function Page(props: {
params: Promise<{ id: string }>;
}) {
const { id } = await props.params;
const initialMessages = await loadChat(id);
return