How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

Migrating resolveProductionUrl from Sanity v2 to v3

6 repliesLast updated: Nov 29, 2025

Hi All. I'm upgrading a studio to v3 and it's all working apart from the production previews. In v2 I was using (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} ``
}

}
But I'm struggling to get it working now. I find the migration docs difficult to understand in this area. Could anyone point me in the right direction? Thanks in advance!
AI Update

I'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.

The Migration

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
    }
  }
})

Key Differences

Alternative: Using document slug

If 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!

Show original thread
6 replies

Was this answer helpful?

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.

Related contributions