
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI'll help you migrate your production preview URL from Sanity Studio v2 to v3. The migration docs can be confusing, but the good news is that the concept is similar - it just needs to be configured in a different location.
In Studio v3, the resolveProductionUrl functionality has been replaced by the productionUrl property in your sanity.config.ts (or .js) file. Here's how to migrate your v2 code:
Your v2 code:
// resolveProductionUrl.js
export default function resolveProductionUrl(document) {
if (document._type == "page"){
return `https://sitename.netlify.app/page-preview/${document._id}`
}
if (document._type == "product"){
return `https://sitename.netlify.app/product-preview/${document._id}`
}
if (document._type == "post"){
return `https://sitename.netlify.app/post-preview/${document._id}`
}
}Your v3 code:
// sanity.config.ts (or .js)
import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
export default defineConfig({
projectId: '<your-project-id>',
dataset: 'production',
plugins: [structureTool()],
schema: {
types: schemaTypes,
},
document: {
productionUrl: async (prev, context) => {
const {document} = context
if (document._type === "page") {
return `https://sitename.netlify.app/page-preview/${document._id}`
}
if (document._type === "product") {
return `https://sitename.netlify.app/product-preview/${document._id}`
}
if (document._type === "post") {
return `https://sitename.netlify.app/post-preview/${document._id}`
}
return prev
}
}
})document property of your main config, not a separate file(prev, context) where the document is available as context.documentprev if none of your conditions matchIf you're using slugs instead of IDs for your preview URLs, you can access them like this:
productionUrl: async (prev, context) => {
const {document} = context
const slug = document?.slug?.current
if (!slug) return prev
if (document._type === "page") {
return `https://sitename.netlify.app/page-preview/${slug}`
}
// ... rest of your conditions
}The preview button should now appear in your document actions bar when editing documents of these types. You can read more about configuring productionUrl in the Studio configuration docs.
Hope this helps with your v3 upgrade!
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store