focusreactive

payload plugin comments

by focusreactive
payload-plugins
Publishing workflow
v3
^3.90.0
MIT

Overview

Summary generated from the README

Adds collaborative comments to the collections and globals you list, shown in a document side panel, a global drawer and badges on field labels. Comments are stored in plugin-owned collections and served through the plugin's own endpoints, with permissions granted through an access policy. Requires Payload 3.90 or later, the companion guard plugin and a config wrapped in its access policy helper.

Features

  • Document-level and field-level comments with a count badge on field labels
  • @mentions with autocomplete limited to users who share the comment's tenant
  • Resolve and reopen comments, with filters for open, resolved and mentioned
  • Email notifications to mentioned users through Resend
  • Four capabilities (view, comment, resolve, moderate) granted in the access policy
  • Multi-tenancy support and locale-aware field comments

Use cases

  • Review content with editors by leaving comments on specific fields before publishing
  • Notify a colleague about a page by mentioning them in a comment
  • Separate comment visibility per tenant in a multi-tenant Payload setup

Installation

npm i @focus-reactive/payload-plugin-comments

37

Stars

5

Forks

33

Open Issues

Today

Last Updated

5.5k

Weekly Downloads

v2.0.1

npm Version

686.0 KB

Unpacked Size

8

Dependencies

Repository stars

37+22 since Sep 6

Show data
Repository stars by day (UTC)
DateStars
Dec 5, 202637
Dec 4, 202637
Dec 3, 202637
Dec 2, 202637
Dec 1, 202636
Nov 30, 202635
Nov 29, 202635
Nov 28, 202634
Nov 27, 202634
Nov 26, 202634
Nov 25, 202634
Nov 24, 202634
Nov 23, 202634
Nov 22, 202634
Nov 21, 202634
Nov 20, 202633
Nov 19, 202632
Nov 18, 202632
Nov 17, 202632
Nov 16, 202632
Nov 15, 202632
Nov 14, 202632
Nov 13, 202632
Nov 12, 202632
Nov 11, 202632
Nov 10, 202632
Nov 9, 202631
Nov 8, 202631
Nov 7, 202631
Nov 6, 202631
Nov 5, 202631
Nov 4, 202630
Nov 3, 202630
Nov 2, 202630
Nov 1, 202630
Oct 31, 202630
Oct 30, 202630
Oct 29, 202630
Oct 28, 202630
Oct 27, 202630
Oct 26, 202630
Oct 25, 202630
Oct 24, 202629
Oct 23, 202629
Oct 22, 202629
Oct 21, 202629
Oct 20, 202629
Oct 19, 202629
Oct 18, 202629
Oct 17, 202627
Oct 16, 202626
Oct 15, 202626
Oct 14, 202626
Oct 13, 202625
Oct 12, 202625
Oct 11, 202625
Oct 10, 202625
Oct 9, 202625
Oct 8, 202625
Oct 7, 202625
Oct 6, 202624
Oct 5, 202624
Oct 4, 202624
Oct 3, 202623
Oct 2, 202622
Oct 1, 202622
Sep 30, 202620
Sep 29, 202620
Sep 28, 202620
Sep 27, 202620
Sep 26, 202619
Sep 25, 202618
Sep 24, 202618
Sep 23, 202618
Sep 22, 202618
Sep 21, 202618
Sep 20, 202618
Sep 19, 202618
Sep 18, 202618
Sep 17, 202618
Sep 16, 202618
Sep 15, 202618
Sep 14, 202618
Sep 13, 202617
Sep 12, 202617
Sep 11, 202617
Sep 10, 202616
Sep 9, 202616
Sep 8, 202616
Sep 7, 202615
Sep 6, 202615

Shared by 15 plugins in focusreactive/payload-plugins.

npm weekly downloads

4.7K+4.2K since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 20264,675
Dec 4, 20264,085
Dec 3, 20262,778
Dec 2, 20262,070
Dec 1, 20261,994
Nov 30, 20261,947
Nov 29, 20261,506
Nov 28, 20264,339
Nov 27, 20264,544
Nov 26, 20266,739
Nov 25, 20269,387
Nov 24, 20269,944
Nov 23, 202611,929
Nov 22, 202614,021
Nov 21, 202613,773
Nov 20, 202613,989
Nov 19, 202611,602
Nov 18, 20269,194
Nov 17, 20268,798
Nov 16, 20266,817
Nov 15, 20265,922
Nov 14, 20263,770
Nov 13, 20265,009
Nov 12, 20268,019
Nov 11, 202610,744
Nov 10, 202615,006
Nov 9, 202619,133
Nov 8, 202620,052
Nov 7, 202620,384
Nov 6, 202619,858
Nov 5, 202617,186
Nov 4, 202614,565
Nov 3, 202610,143
Nov 2, 20266,292
Nov 1, 20267,713
Oct 31, 20267,982
Oct 30, 20267,435
Oct 29, 20266,546
Oct 28, 20266,052
Oct 27, 20268,812
Oct 26, 202612,529
Oct 25, 202611,827
Oct 24, 202611,545
Oct 23, 202610,631
Oct 22, 202611,249
Oct 21, 202612,159
Oct 20, 20269,375
Oct 19, 20265,371
Oct 18, 20263,479
Oct 17, 20263,007
Oct 16, 20263,709
Oct 15, 20263,944
Oct 14, 20265,013
Oct 13, 20265,310
Oct 12, 20266,651
Oct 11, 20266,647
Oct 10, 20267,967
Oct 9, 20269,172
Oct 8, 202611,782
Oct 7, 202611,225
Oct 6, 202611,230
Oct 5, 202610,444
Oct 4, 20269,755
Oct 3, 20268,475
Oct 2, 20266,613
Oct 1, 20263,228
Sep 30, 20261,864
Sep 29, 20261,581
Sep 28, 2026986
Sep 27, 2026973
Sep 26, 20261,057
Sep 25, 20263,325
Sep 24, 20264,530
Sep 23, 20266,976
Sep 22, 20268,547
Sep 21, 20269,662
Sep 20, 202610,578
Sep 19, 202610,433
Sep 18, 20268,174
Sep 17, 20267,014
Sep 16, 20264,747
Sep 15, 20263,315
Sep 14, 20262,308
Sep 13, 20261,190
Sep 12, 2026885
Sep 11, 2026987
Sep 10, 2026993
Sep 9, 2026860
Sep 8, 2026709
Sep 7, 2026604
Sep 6, 2026502

Each point is npm's rolling 7-day download count.

Health Score

75/100Excellent

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1177993877-payload-plugin-comments.svg)](https://payloaddirectory.dev/plugins/1177993877-payload-plugin-comments)
HTML
<a href="https://payloaddirectory.dev/plugins/1177993877-payload-plugin-comments"><img src="https://payloaddirectory.dev/badge/1177993877-payload-plugin-comments.svg" alt="Payload Directory"></a>
Updated Dec 5, 2026Created Mar 10, 2026Published Dec 4, 2026

README

@focus-reactive/payload-plugin-comments

npm

A collaborative commenting plugin for Payload CMS v3. It adds document-level and field-level comments to the collections and globals you name, with @mentions, email notifications, resolution, multi-tenancy and locale-aware filtering.

The plugin is built on @focus-reactive/payload-plugin-guard. Your project's access policy file decides who may read, write, resolve and moderate comments.

Requirements: Payload ^3.90.0, @focus-reactive/payload-plugin-guard, and a config wrapped in withAccessPolicy.

Table of Contents


AI Integration Prompt

Copy and paste this prompt into your AI assistant (Cursor, Claude, etc.) to integrate the plugin into an existing Payload v3 project.

I want to add collaborative comments to my Payload CMS v3 project using
@focus-reactive/payload-plugin-comments. Follow these steps in order, and stop to ask me where a step says so.

## Rules you must follow

- Never write an access rule that admits every logged-in user: no `Boolean(req.user)`, no `() => true`,
  no `({ req }) => !!req.user`. A rule names a role, or it is `nobody`.
- Do not invent roles. Ask me which roles get each capability of the plugin.
- Write every policy entry by hand in `src/access.policy.ts`, and grant each capability and each
  collection right explicitly to the roles I name. Nothing is open by default.
- When the boot or a request fails, fix the cause or ask me. Never use `anyone`, a looser gate,
  `overrideAccess` or a removed or disabled check to make an error go away.
- Do not add `overrideAccess: true` anywhere, and do not add `access` to the `comments` or
  `comment-reads` collections: their policy entries are `nobody` for every operation.

## How it works

The plugin adds comments to the collections and globals listed in its options, and to no others.
It stores them in a `comments` collection and read markers in a `comment-reads` collection.
Only the plugin's own endpoints under `/api/comments-plugin/` read or write them; REST and GraphQL
on both collections are closed for everyone.
The server sets the author, the tenant, the resolver and the mention snapshots; a client cannot send them.
A user sees and comments on a document only when they can read that document.
It declares four capabilities that the project grants in its access policy:
- `view`: see comments, unread mention counts, and mark comments that mention them as read.
- `comment`: write comments, mention users, and delete their own comments.
- `resolve`: resolve and reopen comments.
- `moderate`: delete other users' comments.

## Step 1: install

pnpm add @focus-reactive/payload-plugin-comments @focus-reactive/payload-plugin-guard

Check that `payload` is 3.90 or later; if it is not, upgrade it first.

## Step 2: ask me about roles

Look at the auth collection named in `admin.user` and the roles it has.
Ask me, one question per capability:
"Which roles may see comments?", "Which roles may write comments?",
"Which roles may resolve comments?" and "Which roles may delete other users' comments?"
Wait for my answers. Write each answer as a gate in the policy file in step 3.
Also ask me which collections and globals should have comments, and which field is each collection's title.

## Step 3: the access policy file

Open `src/access.policy.ts`, or create it if the project has none, following the guard README
(`defineAccessPolicy`, `gate`, `filter`, `nobody`, checked with `satisfies AccessPolicy<Config>`).
If you create it, every collection and global of the config needs an entry: move each existing
`access` of the project into the file, and ask me for every rule you cannot read from the code.
Add these entries for this plugin:

collections: {
  comments: { create: nobody, read: nobody, update: nobody, delete: nobody },
  "comment-reads": { create: nobody, read: nobody, update: nobody, delete: nobody },
},
plugins: {
  "comments-plugin": {
    view: <the gate from my first answer>,
    comment: <the gate from my second answer>,
    resolve: <the gate from my third answer>,
    moderate: <the gate from my fourth answer>,
  },
},

## Step 4: register the plugin and wrap the config

// payload.config.ts
import { buildConfig } from 'payload'
import { withAccessPolicy } from '@focus-reactive/payload-plugin-guard'
import { commentsPlugin } from '@focus-reactive/payload-plugin-comments'
import { accessPolicy } from './access.policy'

export default withAccessPolicy(
  accessPolicy,
  buildConfig({
    // ...the existing config
    plugins: [
      commentsPlugin({
        collections: [{ slug: 'pages', titleField: 'title' }],
        globals: ['settings'],
        usernameFieldPath: 'name',
        access: accessPolicy.plugins['comments-plugin'],
      }),
    ],
  })
)

If the project uses @payloadcms/plugin-multi-tenant, add `tenant` as in the plugin README's
"Multi-tenancy" section, with `userHasAccessToAllTenants` set to the same function the
multi-tenant plugin uses.

Run `payload generate:importmap` and `payload generate:types`.
With a SQL adapter, run `payload migrate:create` and `payload migrate`.
Start the app.
A missing or wrong policy entry stops the boot with a list of what to fix.
Fix each item; never loosen a rule to make an error go away.

## Step 5: verify, and show me the output

With the app running, send each request and show me the status code.
Every one of them must be refused. If one succeeds, the policy is wrong: stop and tell me.

1. Anonymous comment, expect 401:
   curl -i -X POST http://localhost:3000/api/comments-plugin/create -H 'Content-Type: application/json' -d '{"collectionSlug":"pages","documentId":1,"text":"hi"}'
2. The same request with the session cookie of a user whose role may not write comments, expect 403.
3. Anonymous list, expect 401:
   curl -i -X POST http://localhost:3000/api/comments-plugin/list -H 'Content-Type: application/json' -d '{}'
4. A direct write to the comments collection with an admin's session cookie, expect 403:
   curl -i -X POST http://localhost:3000/api/comments -H 'Content-Type: application/json' -d '{"text":"hi"}'
5. A direct read of the comments collection with an admin's session cookie, expect 403:
   curl -i http://localhost:3000/api/comments
6. A direct write to the read markers with an admin's session cookie, expect 403:
   curl -i -X POST http://localhost:3000/api/comment-reads -H 'Content-Type: application/json' -d '{}'

Then, as a user who may write comments, open a configured document, post a comment that mentions
a colleague, and check that it appears.

UI Screenshots

Global Comments Panel

A header button in the Payload admin opens a drawer listing all comments across every document and collection.

Global comments panel

Document Comments Panel

When viewing a document, a side panel shows all comments scoped to that document with filter tabs (Open / Resolved / Mentioned me).

Document comments panel

Field Comment Popup

Clicking the comment badge on a field label opens a popup where you can write and post a new comment for that specific field.

Field comment popup

Field Label Button: Two States

The comment button embedded in the field label has two visual states: no comments (inactive, appears on hover) and one or more open comments (active, showing the count badge).

Inactive (no comments)Active (has comments)
Field label button, inactiveField label button, active

Features

  • Document-level comments on the documents of the collections and globals you configure.
  • Field-level comments: the field label shows a badge with the comment count.
  • @mentions with autocomplete, limited to users who share a tenant with the comment.
  • Email notifications to mentioned users through Resend.
  • Resolution: mark comments resolved or open, and filter by open, resolved or mentioned.
  • Global comments panel: a header button opens a drawer with every comment the user may see.
  • Multi-tenancy with @payloadcms/plugin-multi-tenant.
  • Locale-aware: field-level comments belong to a locale; document-level comments show in every locale.
  • Cleanup: deleting a document deletes its comments, and deleting a comment or a user deletes the read markers.
  • Translations for every UI string.

Installation

pnpm add @focus-reactive/payload-plugin-comments @focus-reactive/payload-plugin-guard

Peer dependencies: payload ^3.90.0 and @payloadcms/ui ^3.90.0. next, react and react-dom are optional.


Quick Start

Step 1: Grant the plugin's capabilities in your access policy

The plugin reads every right from your project's access policy file; see the guard README for the whole file. Add the entries for the two collections the plugin owns, and a gate for each capability:

// src/access.policy.ts
import { defineAccessPolicy, gate, nobody } from "@focus-reactive/payload-plugin-guard";
import type { PayloadRequest } from "payload";

const rolesOf = (req: PayloadRequest): string[] =>
  req.user?.collection === "users" ? (req.user.roles ?? []) : [];

const hasRole = (...roles: string[]) =>
  gate(({ req }) => rolesOf(req).some((role) => roles.includes(role)));

const pluginOwned = { create: nobody, read: nobody, update: nobody, delete: nobody };

export const accessPolicy = defineAccessPolicy({
  collections: {
    // ...your collections
    comments: pluginOwned,
    "comment-reads": pluginOwned,
  },
  globals: {
    // ...your globals
  },
  jobs: { run: hasRole("admin"), queue: hasRole("admin"), cancel: hasRole("admin") },
  plugins: {
    "comments-plugin": {
      view: hasRole("admin", "editor", "reviewer"),
      comment: hasRole("admin", "editor", "reviewer"),
      resolve: hasRole("admin", "editor"),
      moderate: hasRole("admin"),
    },
  },
});

Every operation of comments and comment-reads must be nobody; the boot fails otherwise.

Step 2: Register the plugin and wrap the config

// payload.config.ts
import { buildConfig } from "payload";
import { withAccessPolicy } from "@focus-reactive/payload-plugin-guard";
import { commentsPlugin } from "@focus-reactive/payload-plugin-comments";
import { accessPolicy } from "./access.policy";

export default withAccessPolicy(
  accessPolicy,
  buildConfig({
    plugins: [
      commentsPlugin({
        collections: [
          { slug: "pages", titleField: "title" },
          { slug: "products", titleField: "name" },
        ],
        globals: ["settings"],
        usernameFieldPath: "name",
        access: accessPolicy.plugins["comments-plugin"],
      }),
    ],
  })
);

access is required and has no default. The plugin refuses to start without it, and withAccessPolicy checks that it got exactly the gates in accessPolicy.plugins["comments-plugin"]. collections is required too: only the listed collections and globals get comments.

Step 3: Regenerate the import map and migrate

pnpm payload generate:importmap
pnpm payload migrate:create add_comments
pnpm payload migrate

Skip the migration with the MongoDB adapter. The stylesheet loads with the plugin's admin components; there is nothing to import.


Access and capabilities

CapabilityLets a userAlso needs
viewsee comments and unread mention counts, and mark a comment that mentions them as readread access to the commented document
commentwrite comments, see the users they may mention, and delete their own commentsread access to the commented document
resolveresolve and reopen commentsread access to the commented document
moderatedelete other users' commentsview, and read access to the commented document

The capability says who may act at all. The document rights come from the policy entries you already wrote for the commented collections and globals. Every check runs on the server; the admin UI only hides what the capability lookup says the user cannot do. A user without view sees no comment controls at all: no bell in the header, no comment icon next to a field, and no comments drawer. A user with view but without comment sees the comments of a field but no icon to add one.

  • Comments can be created and listed only for a document or global the plugin is configured for, and only when the caller can read it with their own access. An unconfigured slug gets 400, and a document the caller cannot read gets 404.
  • A comment cannot be edited after it is posted. Its author may delete it with comment; anyone else needs moderate.
  • Read markers belong to the user who read the comment; nobody can read or write another user's markers.
  • Anonymous callers get 401; users of another auth collection, users the project's access.admin refuses, and users without the capability get 403.
  • Error bodies are generic; details go to the server log, and refusals are logged at warn with the capability and the caller's kind.
  • GET /api/comments-plugin/capabilities answers a logged-in admin user with { "view": boolean, "comment": boolean, "resolve": boolean, "moderate": boolean } for that user.

What the plugin owns

SlugKindWritten byRead by
commentscollectionthe plugin's endpoints and cascade deletes onlythe plugin's endpoints only
comment-readscollectionthe plugin's endpoints and cascade deletes onlythe plugin's endpoints only

The server sets author, tenant, isResolved, resolvedBy, resolvedAt and the mentions snapshots. A client that sends them, in the body, a cookie or a header, has them ignored.

Endpoints

All endpoints are POST with a JSON body, except the capability lookup.

Path under /api/comments-pluginCapabilityBody
/listview{ collectionSlug, documentId }, { globalSlug }, or {} for every comment the user may see
/unread-mentions-countviewthe same target as /list, plus locale
/document-titlesview{ comments: [{ collectionSlug, documentId }] }
/field-labelsview{ comments: [{ collectionSlug, documentId, globalSlug, fieldPath }] }
/mark-readview{ commentId }
/deleteview, then comment for the author or moderate for anyone else{ id }
/mentionable-userscomment{}
/createcomment{ collectionSlug, documentId } or { globalSlug }, plus text, fieldPath, locale
/resolveresolve{ id, resolved }
GET /capabilitiesa logged-in admin usernone

Limits

  • text: 1 to 5000 characters, with at most 20 mentions.
  • fieldPath: dot-separated names, at most 500 characters.
  • locale: one of the config's locale codes.
  • A list returns the newest 200 comments; the mentionable list returns at most 200 users.
  • Title and label lookups take at most 200 entries.

Multi-tenancy

commentsPlugin({
  collections: [{ slug: "pages", titleField: "title" }],
  access: accessPolicy.plugins["comments-plugin"],
  tenant: {
    enabled: true,
    collectionSlug: "tenants",
    documentTenantField: "tenant",
    tenantsArrayField: { arrayFieldName: "tenants", arrayTenantFieldName: "tenant" },
    userHasAccessToAllTenants: (user) => user.roles?.includes("super-admin") ?? false,
  },
});
  • A comment's tenant is the tenant of the commented document, read on the server. The tenant cookie and the request body play no part.
  • A user's tenants come from their own record (tenants[].tenant by default), or every tenant when userHasAccessToAllTenants returns true. Pass the same function you give @payloadcms/plugin-multi-tenant.
  • A user sees and writes comments only in their tenants. A user without tenants sees none.
  • A global, or a document without a tenant, has no tenant: only users with access to every tenant may comment on it.
  • A user can mention only users who share the comment's tenant.

Mentions and email notifications

Write a mention as @(<user id>) in the text; the editor inserts it from the autocomplete. The server keeps the mentions that name a user of the admin user collection (admin.user) in the comment's tenant, drops the rest, and stores each one's display name as a snapshot. No email address is stored in a comment or sent to the browser.

Mentioned users get one email each, through Resend, when both variables are set:

VariableDescriptionExample
RESEND_API_KEYYour Resend API keyre_xxxxxxxxxxxxxxxx
RESEND_FROM_EMAILSender address for mention notifications[email protected]

Without them, no email is sent and the server logs a warning. The email escapes the comment text and every name. Its link to the document is built from the config's serverURL, or NEXT_PUBLIC_SERVER_URL when serverURL is empty, and the admin route; nothing from the request goes into it.


Configuration Reference

CommentsPluginConfig

OptionTypeDefaultDescription
access{ view, comment, resolve, moderate }requiredThe gates from accessPolicy.plugins["comments-plugin"]
collectionsCollectionEntry[]requiredThe collections whose documents can carry comments
globalsstring[][]The globals that can carry comments
enabledbooleantruefalse removes the endpoints and the admin UI; the collections stay
tenantTenantPluginConfignoneMulti-tenancy settings
overrides{ admin?, hooks?, fields? }noneAdditions to the comments collection
translationsRecord<string, Partial<CommentsTranslations>>noneUI strings per locale
usernameFieldPathstring"name"Dot path to the display name on the admin user collection

CollectionEntry

interface CollectionEntry {
  slug: string;
  titleField?: string;
}

titleField names the field shown as the document's title in the panel. Only that field is read, with the requesting user's access; documents without a titleField, or that the user cannot read, show their id.

usernameFieldPath

The field on the admin user collection used as the display name in comments and the mention autocomplete. It supports dot paths such as profile.displayName. It is the only user field the endpoints return; the email is never used as a name.

TenantPluginConfig

OptionTypeDefaultDescription
enabledbooleanfalseTurn tenant scoping on
collectionSlugstring"tenants"Slug of the tenants collection
documentTenantFieldstring"tenant"Field on commented collections that holds the document's tenant
tenantsArrayField{ arrayFieldName?, arrayTenantFieldName? }{ "tenants", "tenant" }Where the user record lists the user's tenants
userHasAccessToAllTenants(user) => booleanalways falseUsers for whom it returns true act in every tenant

overrides

commentsPlugin({
  // ...
  overrides: {
    admin: { group: "Review" },
    fields: [{ name: "priority", type: "select", options: ["low", "high"] }],
    hooks: { afterChange: [notifySlack] },
  },
});

admin is merged into the plugin's settings, fields are appended, and hooks run after the plugin's own. When a commented document is deleted, its comments and their read markers are removed in batches through the database adapter, so the beforeDelete and afterDelete hooks of overrides.hooks do not run for them; they run when a comment is deleted through the plugin's endpoint. Access cannot be overridden: it comes only from the access policy.


Translations

Use translations to override any UI string for one or more locales. Each key is a locale code; the value is a partial object of the CommentsTranslations shape. Keys you omit fall back to the built-in English defaults.

commentsPlugin({
  translations: {
    fr: {
      label: "Commentaires",
      add: "Ajouter un commentaire",
      writeComment: "Écrire un commentaire",
      comment: "Commenter",
      cancel: "Annuler",
      resolve: "Résoudre",
      reopen: "Rouvrir",
      delete: "Supprimer",
      filterOpen: "Ouverts",
      filterResolved: "Résolus",
      filterMentioned: "Me mentionnent",
    },
  },
});

All translatable keys (with their English defaults):

KeyDefault (English)
label"Comments"
openComments_one"{{count}} open comment"
openComments_other"{{count}} open comments"
add"Add comment"
writeComment"Write a comment"
comment"Comment"
cancel"Cancel"
posting"Posting…"
resolve"Resolve"
reopen"Reopen"
delete"Delete"
general"General"
close"Close"
syncingComments"Syncing comments"
openCommentsAria"Open comments"
failedToPost"Failed to post comment"
failedToUpdate"Failed to update comment"
failedToDelete"Failed to delete comment"
failedToAdd"Failed to add comment"
unknownAuthor"Unknown"
deletedUser"Deleted user"
noOpenComments"No open comments"
noResolvedComments"No resolved comments"
noMentionedComments"No comments mentioning you"
filterOpen"Open"
filterResolved"Resolved"
filterMentioned"Mentioned me"
noMentionMatches"No matches"

The CommentsTranslations type is exported from the package so you can type your translation objects:

import type { CommentsTranslations } from "@focus-reactive/payload-plugin-comments";

const myTranslations: Record<string, Partial<CommentsTranslations>> = {
  fr: { label: "Commentaires" },
  de: { label: "Kommentare" },
};

commentsPlugin({ translations: myTranslations });

Migrating from 1.x

2.0 moves the plugin onto @focus-reactive/payload-plugin-guard; Upgrading to the guard explains the model all the plugins share, with a complete example. Every access rule is now written by hand in your project's src/access.policy.ts, and nothing is open by default: an entry you leave out stops the boot, and a capability you do not grant is refused for everyone.

What changes

  • Payload and every @payloadcms/* package 3.90 or later, with the React and Next versions Payload 3.90 requires, Node 22.22 or later, and @focus-reactive/payload-plugin-guard installed next to the plugin.
  • access is a required option with four capabilities and no default.
  • collections is required, and only the listed collections get comments; list the globals that should have comments in globals. In 1.x every collection and global had comments.
  • REST and GraphQL on comments and comment-reads are closed for everyone; code that read or wrote comments through /api/comments uses the plugin's endpoints under /api/comments-plugin/ instead, whose paths are unchanged.
  • overrides.access is gone, overrides.fields is an array of fields to append instead of a function, and overrides.hooks run after the plugin's hooks instead of replacing them.
  • enabled: false turns off the endpoints and the admin UI but keeps the two collections, so their policy entries stay.
  • Comments can no longer be edited, and deleting another user's comment needs moderate.
  • When a commented document is deleted, its comments are removed through the database adapter, so the delete hooks of overrides.hooks do not run for them.
  • With multi-tenancy, the tenant comes from the commented document and the user's tenants from the user record, never from the tenant cookie. Users without tenants, and comments on globals, are limited to users with userHasAccessToAllTenants; existing comments keep their stored tenant.
  • Mentions are limited to 20 per comment and to users of the comment's tenant, the user lookup uses the collection in admin.user instead of users, and no email address is stored or returned.
  • @payloadcms/plugin-multi-tenant is no longer a peer dependency.

Steps

  1. Upgrade payload and every @payloadcms/* package to 3.90 or later, run the server on Node 22.22 or later, and install the guard: pnpm add @focus-reactive/payload-plugin-guard @focus-reactive/payload-plugin-comments.

  2. Add the plugin's entries to src/access.policy.ts, with gates for your own roles; if the project has no policy file yet, write it first as the guide describes.

    // src/access.policy.ts, inside defineAccessPolicy({ ... })
    collections: {
      comments: { create: nobody, read: nobody, update: nobody, delete: nobody },
      "comment-reads": { create: nobody, read: nobody, update: nobody, delete: nobody },
    },
    plugins: {
      "comments-plugin": {
        view: isReviewer,
        comment: isReviewer,
        resolve: isEditor,
        moderate: isAdmin,
      },
    },
    
    • view: see comments and unread mention counts, and mark a comment that mentions the user as read.
    • comment: write comments, see the users they may mention, and delete their own comments.
    • resolve: resolve and reopen comments.
    • moderate: delete other users' comments; it needs view as well.
    • Every capability also needs read access to the commented document; comments and comment-reads are written and read only through the plugin, so every operation stays nobody.
  3. Pass access: accessPolicy.plugins["comments-plugin"] to commentsPlugin, and export the config wrapped: export default withAccessPolicy(accessPolicy, buildConfig({ ... })).

  4. Database: no migration; the two collections keep their columns.

  5. Re-test: an anonymous POST /api/comments-plugin/list answers 401, a user of another auth collection 403, and GET /api/comments as an admin 403; a user without moderate cannot delete another user's comment; then write, mention, resolve and delete a comment as the roles you granted.


Architecture Overview

  • plugin.ts creates the plugin with createGuardedPlugin, adds the comments and comment-reads collections with every operation locked, and registers the endpoints under /api/comments-plugin/.
  • It adds a field-label component and an afterDelete cascade to each configured collection, the field-label component to each configured global, and a beforeDelete cascade for read markers to the admin user collection.
  • The admin UI (CommentsProviderWrapper, CommentsHeaderButton) fetches through the endpoints with TanStack Query and updates its cache optimistically.
  • The endpoints read the commented document as the caller to decide whether the caller may see it, and use the plugin's system access only for the two collections it owns and for display names of the admin user collection.

Comments collection schema:

FieldTypeDescription
documentIdnumberID of the commented document (null for globals)
collectionSlugtextSlug of the collection (null for globals)
globalSlugtextSlug of the global (null for collection documents)
fieldPathtextDot path of the field (null for document-level comments)
localetextLocale of the comment (null shows in every locale)
texttextareaComment body, with @(userId) mention tokens
mentionsarrayMentioned users with their display-name snapshots
authorrelationshipThe author, set by the server
isResolvedcheckboxWhether the comment is resolved
resolvedByrelationshipWho resolved it, set by the server
resolvedAtdateWhen it was resolved, set by the server
tenantrelationshipThe commented document's tenant, when multi-tenancy is on

Exports Reference

Import pathExports
@focus-reactive/payload-plugin-commentscommentsPlugin, CommentsPluginConfig (type), CommentsTranslations (type)

Available Scripts

CommandDescription
pnpm buildBuild the plugin to dist/
pnpm devBuild in watch mode
pnpm lintLint and check formatting (Ultracite)
pnpm lint:fixLint and fix, including formatting
pnpm testUnit tests and integration tests on a temporary SQLite database

License

MIT © Focus Reactive

Similar plugins