# Comments

- Human documentation: [https://docs.univer.ai/guides/bases/features/thread-comment](https://docs.univer.ai/guides/bases/features/thread-comment)

- Agent Markdown: [https://docs.univer.ai/guides/bases/features/thread-comment.md](https://docs.univer.ai/guides/bases/features/thread-comment.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [bases/features/thread-comment.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/bases/features/thread-comment.mdx)

---

#### Package metadata

```json
{
  "preset": [],
  "plugins": [
    {
      "client": "@univerjs/thread-comment",
      "facade": "@univerjs/thread-comment/facade"
    },
    {
      "client": "@univerjs/thread-comment-ui",
      "locale": "@univerjs/thread-comment-ui/locale/en-US",
      "style": "@univerjs/thread-comment-ui/lib/index.css"
    },
    {
      "client": "@univerjs-pro/bases-thread-comment",
      "facade": "@univerjs-pro/bases-thread-comment/facade"
    },
    {
      "client": "@univerjs-pro/bases-thread-comment-ui",
      "locale": "@univerjs-pro/bases-thread-comment-ui/locale/en-US",
      "style": "@univerjs-pro/bases-thread-comment-ui/lib/index.css"
    }
  ],
  "server": "optional"
}
```

Discuss tasks, orders, and other records. Comments stay attached to the record across Grid, Kanban, Gallery, Calendar, and Gantt views; switching views does not create a separate discussion.

## Register the plugins

Add these after the Bases core and UI plugins:

#### npm

```bash
npm install @univerjs-pro/bases-thread-comment @univerjs-pro/bases-thread-comment-ui
```

#### pnpm

```bash
pnpm add @univerjs-pro/bases-thread-comment @univerjs-pro/bases-thread-comment-ui
```

#### yarn

```bash
yarn add @univerjs-pro/bases-thread-comment @univerjs-pro/bases-thread-comment-ui
```

#### bun

```bash
bun add @univerjs-pro/bases-thread-comment @univerjs-pro/bases-thread-comment-ui
```

```ts
import { UniverBasesThreadCommentPlugin } from '@univerjs-pro/bases-thread-comment'
import { UniverBasesThreadCommentUIPlugin } from '@univerjs-pro/bases-thread-comment-ui'

import '@univerjs-pro/bases-thread-comment/facade'
import '@univerjs/thread-comment/facade'
import '@univerjs-pro/bases-thread-comment-ui/lib/index.css'

univer.registerPlugin(UniverBasesThreadCommentPlugin)
univer.registerPlugin(UniverBasesThreadCommentUIPlugin)
```

Merge the comment packages' locale resources and configure the current application user. The UI plugin adds record comment controls; the data plugin associates comments with records.

## Add and read comments

```ts
const record = univerAPI.getActiveBase()?.getTables()[0]?.getRecords()[0]
if (!record) throw new Error('Create a record first')

await record.createCommentAsync('Please confirm the delivery date.')
const comments = record.getComments()
console.log(comments.map(({ root }) => root.id))
```

`getComments()` reads locally loaded comments. With a remote data source, `await record.listCommentsAsync()` synchronizes known threads before returning them. See [comment Facade](https://docs.univer.ai/reference/facade/thread-comment.md) for replies, updates, and deletion.

## Saving and shared discussions

Local comments can be saved as Base resources through `base.save()`. Register the comment plugins before restoring a snapshot.

Shared discussions also need a comment service, data source, and permissions. Document collaboration alone does not connect comments. Follow [Office extension modules](https://docs.univer.ai/server/collaboration/extensions.md), then test creation, reading, permissions, and reopening with two accounts.

## Shared comment operations

Import both the shared comment Facade and the product Facade before calling these methods. Product helpers create stable anchors; the shared API handles replies, updates, resolution, and deletion. `getComments()` reads local state. `listCommentsAsync()` synchronizes already known threads through the configured data source; it does not discover every thread on the server.

```ts
import '@univerjs/thread-comment/facade'

const [thread] = univerAPI.getComments({ resolved: false })
if (thread) {
  await univerAPI.replyCommentAsync({
    unitId: thread.unitId,
    subUnitId: thread.subUnitId,
    threadId: thread.threadId,
    content: 'Reviewed.',
  })
}
```

## Shared discussions

For shared discussions, integrate the Comment Service and Endpoint with [Server SDK](https://docs.univer.ai/server/collaboration/extensions.md), then register `UniverThreadCommentDataSourcePlugin` from `@univerjs-pro/thread-comment-datasource` after collaboration and license setup. The supplied data source uses `/universer-api/comment/unit/{unitId}/...` and `/universer-api/user/list`; expose those routes through your application. Server permissions must cover comment reads and writes independently of document editing.
