How to set document actions in Sanity Studio v3?
In Studio v3, the __experimental_actions property has been replaced with a more robust configuration system. Here's how to achieve the same behavior for singleton documents like site settings:
Using document.actions in Studio v3
In your sanity.config.ts (or .js), use the document.actions configuration to filter which actions appear on documents:
import {defineConfig} from 'sanity'
export default defineConfig({
// ... other config
document: {
// Filter document actions
actions: (prev, context) => {
// For singleton documents like site settings
if (context.schemaType === 'siteSettings') {
// Only allow publish action (equivalent to ["update", "publish"])
return prev.filter(({action}) => action === 'publish')
}
return prev
},
// Prevent creating new documents of this type
newDocumentOptions: (prev, context) => {
return prev.filter(
(template) => template.templateId !== 'siteSettings'
)
}
}
})What Changed from v2 to v3
The v3 approach provides more flexibility and control:
document.actions: Replaces__experimental_actionsfor filtering which actions (publish, delete, duplicate, etc.) appear on documents. You receive the full list of default actions and can filter or reorder them based onschemaTypeor other context.document.newDocumentOptions: Controls what appears in the "Create new document" menu, preventing users from creating multiple instances of singleton documents.
Complete Singleton Pattern
Here's a complete example that properly restricts a singleton document:
// Array of document types that should be singletons
const singletonTypes = ['siteSettings', 'homePage']
export default defineConfig({
// ... other config
document: {
actions: (prev, context) => {
if (singletonTypes.includes(context.schemaType)) {
// Only allow publish action for singletons
return prev.filter(({action}) => action === 'publish')
}
return prev
},
newDocumentOptions: (prev, context) => {
// Remove singletons from "Create new" menu
return prev.filter(
(template) => !singletonTypes.includes(template.templateId)
)
}
}
})Additional Benefits
The v3 approach gives you access to more context, allowing you to:
- Filter actions based on user roles (
context.currentUser) - Customize behavior per document type
- Add custom actions alongside default ones
- Reorder actions in the toolbar
You can also combine this with Structure Builder to create dedicated menu items that always open your singleton documents, making them feel like true settings pages rather than document lists.
Show original thread4 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.