Enable and configure Comments
Learn how to enable and configure the Comments feature in Sanity Studio.
Comments are available for all paid plans in Sanity Studio. This article walks studio maintainers through enabling and configuring comments for their projects.
Paid feature
This article discusses a feature that is available for projects on the Growth plan and up. Visit our pricing page to learn about Sanity's different plan offerings.
- Sanity Studio v3.40.0 or later (latest is always recommended)
- Project on a supported plan
Permissions needed for tasks and comments
All roles need to have these permissions to be able to use comments and tasks fully:
Management permissions
"Project details" read
=> For feature flag
"Project members" read
=> @mention members
"Project datasets" read
=> View all comments with count
Content permissions
"All documents" read
on main dataset(s) used in your Studio/workspaces
Comments are enabled by default for all paid plans. To disable comments, set document.comments.enabled
to false
in your studio configuration file:
// ./sanity.config.ts|js
export default defineConfig({
// ... rest of config
document: {
comments: {
enabled: false,
},
},
});
Gotcha
Disabling comments hides them in the studio, but existing comments persist in the add-on comment dataset.
To enable comments only for specific document types, use an arrow function:
// ./sanity.config.ts|js
export default defineConfig({
// ... rest of config
document: {
comments: {
enabled: (ctx) => {
return ctx.documentType == 'whitepaper';
},
},
},
});
To enable comments for multiple document types, use an array:
// ./sanity.config.ts|js
const COMMENTS_ENABLED = ['article', 'blog', 'whitepaper'];
export default defineConfig({
// ... rest of config
document: {
comments: {
enabled: (ctx) => {
return COMMENTS_ENABLED.includes(ctx.documentType);
},
},
},
});
To keep everything neat and tidy, comments are stored parallel to your content in a complimentary dataset, along with other workflow and collaboration data, such as Comments.
These datasets:
- Do not count toward the data limit of your current plan.
- Do not incur any extra costs for your project.
- Are listed in the project management pages under Datasets, along with all existing datasets for a project.
- Include a distinctive suffix in the dataset name. This is a best-effort attempt, and the result may vary, depending on the character length of the name of the related document dataset. Examples:
<related-document-dataset>-comments
-
<related-document-dataset>-cmts
-
<related-document-dataset>-cmt
-
<related-document-dataset>-c
- Are searchable: you can query comment datasets with GROQ or GraphQL. This means they can also be used with GROQ-powered Webhooks.
Gotcha
Deleting an add-on comment dataset permanently removes all comments. To restore commenting after deletion, reload the studio instance to create a new, empty comment dataset.
When you export or Cloud Clone a dataset, the comments don’t migrate with the data. To copy comments to a new dataset or studio, you’ll need to perform the following steps:
- Identify the name of the comment dataset you wish to copy
- Export the comment dataset
- Enable comments in the new primary dataset and identify the name of the comments dataset
- Import the comment dataset file into the new comment dataset
- Confirm that the process was successful
For the following examples, we’ll use the terms “production” and “staging” to represent the original and new primary datasets. If you haven’t already, make sure to Cloud Clone your primary dataset.
Comments live alongside regular datasets in an add-on dataset. You can find the name by visiting manage, selecting your project, and selecting the datasets screen. You can also run the dataset list
command in the CLI.
Input
npx sanity@latest dataset list
Output
production production-comments staging
Make note of the name of the comments dataset that matches your primary dataset. In this case, production-comments
.
Export the comment dataset to a local file using the dataset export
command.
npx sanity@latest dataset export production-comments production-comments-export.tar.gz
Make note of the file name and location. You'll need it shortly.
If you haven't already, reload Sanity Studio with the new primary dataset configured.
// sanity.config.ts
export default defineConfig({
// ... rest of config
dataset: 'staging'
})
If the dataset list
command does not list a comments add-on dataset for your primary dataset, such as staging-comments
, you'll need to trigger the creation of the dataset by manually making a comment in Sanity Studio. Once that's done, you should see the new comments dataset in the results of dataset list
.
Input
npx sanity@latest dataset list
Output
production production-comments staging staging-comments
Use the dataset import
command to import the local comments export into the new comments dataset.
npx sanity@latest dataset import production-comments-export.tar.gz staging-comments
Reload and visit your Studio. Confirm that the imported comments are as expected and delete the test comment if you created one earlier.