# Chat thread

A message history that follows new replies while preserving your place in older messages.

Access: pro. Category: Blocks. Kind: composite.

## When to use

- Use it when a page needs a message history that follows new replies while preserving your place in older messages.
- Choose it inside an authenticated product surface when the host application owns routing, persistence, and service calls.

## Alternatives

- Choose empty-state instead when empty collections, search results and errors with a clear next action is the actual interface need, rather than chat thread.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Chat thread

```sh
npx shadcn@latest add @tidal-pro/chat-thread
```

Stylesheets: `components/ui/tidal.css`, `components/ui/chat-thread.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/chat-thread.css";
import{TidalChatThread}from"./components/ui/chat-thread";
export default()=><div className="tidal-scope"><TidalChatThread label={"Demo"} messages={[{id:"example",author:"value",content:"value"}]}/></div>;
```

## Structured props

- `TidalChatThread.label: string`: Required label value accepted by this exported component.
- `TidalChatThread.messages: ReadonlyArray<TidalChatMessage>`: Required messages value accepted by this exported component.
- `TidalChatThread.announceUpdates?: boolean | undefined` (default false): Optional announce updates value accepted by this exported component.
- `TidalChatThread.emptyMessage?: ReactNode` (default "No messages yet."): Optional empty message value accepted by this exported component.
- `TidalChatThread.followLatest?: boolean | undefined` (default true): Optional follow latest value accepted by this exported component.
- `TidalChatThread.initialScroll?: "start" | "end" | undefined` (default "end"): Optional initial scroll value accepted by this exported component.
- `TidalChatThread.maxHeight?: number | undefined` (default 520): Optional max height value accepted by this exported component.
- `TidalChatThread.title?: ReactNode`: Optional title value accepted by this exported component.
- `TidalChatThread.viewportProps?: Omit<Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "role" | "aria-atomic" | "aria-label" | "aria-live" | "aria-relevant" | "children"> | undefined` (default {}): Optional viewport props value accepted by this exported component.
- `TidalChatThread.viewportRef?: Ref<HTMLDivElement> | undefined`: Optional viewport ref value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/chat-thread.tsx) | [Manifest](https://tidalui.com/examples/chat-thread.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import { useState } from "react";

import { TidalChatThread, type TidalChatMessage } from "./components/ui/chat-thread";

import "./components/ui/chat-thread.css";

function tidalExampleAvatarDataUri(seed: unknown) {
  const text = String(seed).replace(/[^a-z0-9]/gi, "").slice(-2) || "UI";
  const palette = ["#333333", "#555555", "#777777", "#999999", "#bbbbbb"];
  const color = palette[Array.from(text).reduce((sum, character) => sum + character.charCodeAt(0), 0) % palette.length];
  const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96"><rect width="96" height="96" rx="48" fill="${color}"/><circle cx="48" cy="38" r="17" fill="white" fill-opacity=".92"/><path d="M18 92c3-22 15-34 30-34s27 12 30 34" fill="white" fill-opacity=".92"/></svg>`;
  return `data:image/svg+xml,${encodeURIComponent(svg)}`;
}

function tidalExampleImageDataUri(label: string) {
  const safeLabel = label.replace(/[<>&]/g, "").slice(0, 28) || "Sample image";
  const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 675"><defs><linearGradient id="g" x1="0" x2="1" y1="0" y2="1"><stop stop-color="#171717"/><stop offset="1" stop-color="#555555"/></linearGradient></defs><rect width="1200" height="675" fill="url(#g)"/><circle cx="950" cy="100" r="260" fill="white" fill-opacity=".08"/><text x="80" y="570" fill="white" font-family="system-ui,sans-serif" font-size="64" font-weight="700">${safeLabel}</text></svg>`;
  return `data:image/svg+xml,${encodeURIComponent(svg)}`;
}

const tidalExampleStyles = ".tidal-scope .chat-thread-demo {\n  width: min(100%, 660px);\n  min-width: 0;\n}\n.tidal-scope .chat-thread-demo-controls {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 8px;\n  margin-bottom: 14px;\n}\n.tidal-scope .chat-thread-demo-controls > button {\n  min-height: 44px;\n  padding: 9px 13px;\n  background: var(--t-surface);\n  color: var(--t-ink);\n  border: 1px solid var(--t-border);\n  border-radius: 9px;\n  font: inherit;\n  font-size: 12px;\n}\n.tidal-scope .chat-thread-demo > p {\n  margin: 14px 2px 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.6;\n}";

const initial: TidalChatMessage[] = [
  {
    id: "one",
    author: "Avery",
    outgoing: true,
    timestamp: "9:41 AM",
    avatar: <img src={tidalExampleAvatarDataUri("01")} alt="" />,
    content: "Could you check the new account settings before launch?",
    deliveryText: "Read",
  },
  {
    id: "two",
    author: "Mila",
    timestamp: "9:42 AM",
    avatar: <img src={tidalExampleAvatarDataUri("03")} alt="" />,
    content:
      "The form looks good. I checked the mobile layout and keyboard controls.",
  },
  {
    id: "three",
    author: "Avery",
    outgoing: true,
    timestamp: "9:43 AM",
    avatar: <img src={tidalExampleAvatarDataUri("01")} alt="" />,
    content: "Thanks. I'll add those checks to the release notes.",
    deliveryText: "Delivered",
  },
];

export function ChatThreadDemo() {
  const [messages, setMessages] = useState(initial);
  return (
    <div className="chat-thread-demo">
      <div className="chat-thread-demo-controls">
        <button
          type="button"
          onClick={() =>
            setMessages((old) => [
              ...old,
              {
                id: `reply-${old.length}`,
                author: "Mila",
                timestamp: "9:44 AM",
                content: "The updated release notes are ready for review.",
              },
            ])
          }
        >
          Add sample reply
        </button>
        <button type="button" onClick={() => setMessages(initial)}>
          Reset
        </button>
      </div>
      <TidalChatThread
        label="Project conversation"
        messages={messages}
        maxHeight={420}
      />
      <p>Local sample messages. Nothing is sent.</p>
    </div>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <ChatThreadDemo />
    </div>
  );
}

```

## Gotchas

- The host application owns data, validation, persistence, navigation, and service side effects described by this API.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

messages require unique ids, author names and consumer-owned ReactNode content. Optional outgoing style, avatar, timestamp/dateTime, deliveryText and actions per message. label names the scrollable log; optional title, emptyMessage, maxHeight (520px default), followLatest(defaulttrue), initialScroll(end default), announceUpdates(defaultfalse), viewportProps/ref, and native section attributes/ref. New messages follow only while already at the bottom; otherwise a jump-to-latest control shows a count. Stable visible-message anchoring preserves position through prepends and content resizing. Consumers own message generation, delivery, retry/copy actions, content safety and persistence. No request, transport or storage is implemented.
