# Split threads

Two threads side by side, for comparing models or prompts: one composer for either side or both, linked scrolling, and swap.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Split threads. Two prompt variants on the same model get one question at once, are read side by side, then swap sides. Preview: https://chatcn.dev/preview/split-threads-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/split-threads
```

## Usage

```tsx
import { SplitThreads } from "@/components/ui/chatcn/pro/split-threads"

<SplitThreads
  panes={[
    { id: "a", title: "Prompt A", subtitle: "concise", messages: a.messages, status: a.status },
    { id: "b", title: "Prompt B", subtitle: "with examples", messages: b.messages, status: b.status },
  ]}
  onSend={(ids, text) => ids.forEach((id) => ask(id, text))}
  onReorder={setOrder}
/>
```

Each side is its own thread with its own status, so one can still be answering while the other is done or has failed. One composer sends to Both, or to one side, so a comparison asks the same question twice without retyping it. Scroll together keeps the two answers level as you read, by proportion, so a long answer and a short one stay aligned; turn it off to read them apart. Swap sides puts the one you prefer where you want it; Close turns the layout back into one thread through `onClose`. On a host narrower than 720 px the sides stack behind a switch.

## Examples

### States

Example: States. Both answered with close and swap, one still answering, and one side failed. Preview: https://chatcn.dev/preview/split-threads-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `panes` | `[SplitPane, SplitPane]` | `{ id, title, subtitle?, messages, status?, error?, onRetry?, onStop? }` |
| `onSend` | `(ids, text) => void` | `ids` is one side or both |
| `onReorder` | `([a, b]) => void` | Shows Swap sides |
| `onClose` | `(id) => void` | Shows a close button on each side |
| `defaultLinked` | `boolean` | Scroll together. Default on |
| `value`, `onValueChange` | `string` | The draft, controlled or not |
| `disabled` | `boolean` |  |
| `labels` | `Partial<SplitThreadsLabels>` | Every string, for translation |

## Keyboard

| Key | Action |
| --- | --- |
| Arrow keys in Send to | Choose Both or one side |
| Enter, Shift Enter | Send, new line |
| Escape | Stop both answers while they stream |

## Accessibility

- Each side is a labelled region with its own polite live region, so both answers are announced.
- Send to is a toggle group, and the input's placeholder says where the message will go.
- Scroll together is a pressed or not pressed button with its state in the label.
- On phones the hidden side is removed from the accessibility tree, not just covered.

## Motion

Sides enter with a short rise when they appear or swap. Linked scrolling moves the other side with no easing of its own. Under reduced motion sides appear in place.

Source: https://chatcn.dev/docs/components/split-threads