Connection state
A small inline status pill for streaming connections that shows when the socket drops, reconnects, or resumes the stream. It renders nothing while the phase is "online".


Installed with shadcn add · 1 workaround · theme from registry.json
- installed base item https://r.assistant-ui.com/shimmer-style.json (registry preview settings)
Installation
Requires @assistant-ui in the registries of your components.json (shadcn adds official directory namespaces automatically).
Usage
import { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function Status({ phase, onRetry }: { phase: "online" | "dropped" | "reconnecting" | "resumed"; onRetry: () => void }) { return <ConnectionState phase={phase} onRetry={onRetry} />;}- Show it when the streaming socket drops while the server-side run continues, so users know nothing was lost.
- Use the onRetry callback to offer a manual Reconnect action during the dropped phase.
- Display the attempt counter while automatic reconnection is in progress.
- Confirm recovery with the resumed phase and the number of tokens picked up from the stream.
Examples
Dropped with manual retry
Shows the amber lost-connection message and a Reconnect button that calls onRetry.
import { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function DroppedExample() { return <ConnectionState phase="dropped" onRetry={() => console.log("retry")} />;}Reconnecting with attempt counter
Shows the spinner and the current reconnection attempt number.
import { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function ReconnectingExample() { return <ConnectionState phase="reconnecting" attempt={3} />;}Resumed with token count
Confirms the stream was picked back up and shows how many tokens were recovered.
import { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function ResumedExample() { return <ConnectionState phase="resumed" resumedTokens={128} className="mx-auto" />;}Live region for screen readers
Passes standard div attributes through to the root so the status can be announced.
import { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function LiveExample({ phase }: { phase: "online" | "dropped" | "reconnecting" | "resumed" }) { return <ConnectionState phase={phase} role="status" aria-live="polite" />;}API reference
Accessibility
- The source sets no role or aria-live on the root; pass role="status" and aria-live="polite" if the phase change should be announced to screen readers.
- The Reconnect control is a real button with type="button" and visible text, so it is keyboard-focusable and labelled.
- Icons have no aria-label; the adjacent text conveys the state, so they are decorative.
- The spinner uses motion-reduce:animate-none to respect reduced-motion preferences.
- The fade-in and slide animation classes do not include a motion-reduce override in the source; add one in your app CSS if needed.
- Text colors rely on the paper surface and foreground tokens; verify contrast of the amber and emerald icons in both light and dark themes.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "Connection state" component (assistant-ui/elements-connection-state) from its shadcn registry.1. Install it with: npx shadcn@latest add @assistant-ui/elements-connection-state2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: phase, attempt, resumedTokens, onRetry, className, ...props.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ConnectionState } from "@/components/assistant-ui/elements/connection-state";export function Status({ phase, onRetry }: { phase: "online" | "dropped" | "reconnecting" | "resumed"; onRetry: () => void }) { return <ConnectionState phase={phase} onRetry={onRetry} />;}```Files & dependencies
- components/assistant-ui/elements/connection-state.tsx