# Version History

> Document version history in the Google Docs mould: versions grouped by day with author colors, named versions, and runs of autosaves folded under a caret. The selected version renders on a page with word-level changes from the one before in its author's color, behind a Show changes switch. Name a version in place, make a copy, or restore after a confirm. Narrow widths swap the list for a select.

- Slug: `version-history`
- Category: [Timelines](https://www.assembli.design/category/timelines.md)
- Type: component
- Tags: version-history, revisions, diff, restore, document, timeline
- npm dependencies: @base-ui/react, lucide-react
- shadcn/ui dependencies: none
- Live preview: https://www.assembli.design/preview/version-history
- Page: https://www.assembli.design/components/version-history

![Version History preview](https://www.assembli.design/thumbnails/version-history-light.png)

## Props

Other props pass through to the root element.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `versions` | `DocVersion[]` |  | Newest first. The first one is the current version. |
| `defaultVersions` | `DocVersion[]` | `[]` |  |
| `onVersionsChange` | `(versions: DocVersion[]) => void` |  |  |
| `documentTitle` | `string` | `"Untitled document"` |  |
| `you` | `VersionAuthor` | `{ name: "You", color: "#2563eb" }` | Who restores, for the version a restore adds. |
| `onRestore` | `(version: DocVersion) => Promise<unknown> \| void` |  | Called before a restore lands. Reject to cancel it. |
| `onCopy` | `(version: DocVersion) => Promise<unknown> \| void` |  |  |
| `onRename` | `(version: DocVersion, name: string) => void` |  |  |
| `now` | `string \| number \| Date` |  | For "Today" and "Yesterday". Pass it so server and browser agree. |
| `timeZone` | `string` |  | IANA zone for times. Pass it so server and browser agree. |
| `locale` | `string` | `"en-US"` |  |
| `container` | `HTMLElement \| null` |  | Renders the restore dialog inside this element instead of the body. |
| `title` | `React.ReactNode` | `"Version history"` |  |

## Install

One-time setup (needs a subscription):

1. Add the registry to the project's `components.json`: `{"@assembli":{"url":"https://www.assembli.design/r/{name}.json","headers":{"Authorization":"Bearer ${ASSEMBLI_API_KEY}"}}}` (merge into `"registries"`).
2. Put an API key from https://www.assembli.design/account in `.env.local` as `ASSEMBLI_API_KEY=asm_…`.

Then install with the shadcn CLI (writes `components/version-history/version-history.tsx` and installs dependencies):

```bash
npx shadcn@latest add @assembli/version-history
```

Registry item JSON: https://www.assembli.design/r/version-history.json (send `Authorization: Bearer <api key>`)

## Code

> Component source needs an Assembli subscription ($12/month or $96/year) and an API key sent as `Authorization: Bearer <key>`. To get one without copying anything, POST https://www.assembli.design/api/agent/login (or call the MCP tool connect_account), show the user the link it returns, and poll https://www.assembli.design/api/agent/token for the key. Or subscribe at https://www.assembli.design/pricing and create a key at https://www.assembli.design/account.
