
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeLooking at your schema, you're dealing with nested arrays and union types, which makes preview selection tricky. The good news is that Sanity's select in preview configuration supports accessing nested properties, and you can handle the union type logic in the prepare function.
Your intuition is correct - you'll need to select the fields you need using dot notation and then determine the type in prepare. Here's the recommended approach:
// productionContent.js
export default {
name: 'productionContent',
title: 'Content',
type: 'object',
fields: [{
name: 'content',
title: 'Content',
type: 'content',
}],
preview: {
select: {
// Select the first item's type to determine photo vs video
contentType: 'content.0._type',
// Select photo fields
photoImage: 'content.0.image',
photoFilename: 'content.0.image.asset.originalFilename',
// Select video fields
videoTitle: 'content.0.title',
videoImage: 'content.0.image',
},
prepare(selection) {
const { contentType, photoImage, photoFilename, videoTitle, videoImage } = selection;
if (contentType === 'photo') {
return {
title: photoFilename || 'Untitled Photo',
subtitle: 'Photo',
media: photoImage,
}
}
if (contentType === 'video') {
return {
title: videoTitle || 'Untitled Video',
subtitle: 'Video',
media: videoImage,
}
}
return {
title: 'No content',
}
}
}
}The key points:
Use content.0._type to determine which union type you're dealing with. Every Sanity object has a _type field that identifies its schema type.
Select all possible fields you might need from both photo and video types. The ones that don't exist for the actual type will just be undefined.
Branch in prepare based on the _type to return the appropriate title, subtitle, and media.
This is indeed the standard pattern for handling union types in preview configurations. While it feels verbose, it's the most reliable way to handle polymorphic content in Sanity previews.
Alternative consideration: If your content array typically only has one item (which seems to be the case from your schema structure), you might want to reconsider if you need the array wrapper at all. If productionContent.content is always a single item, you could make it a direct union type instead of an array, which would simplify your preview configuration to just content._type, content.image, etc. without the array indexing.
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