Sanity V3 Desk Tool Crash: Empty Media Properties in Preview Prepare
Great to hear you solved it! This is actually a common gotcha when migrating from Studio v2 to v3. The media property handling in preview configuration became stricter in v3.
In Studio v2, the preview system was more forgiving about empty or undefined media properties, but v3 requires them to be either a valid value or explicitly handled. When you have a prepare function that returns an empty media property, it can cause the desk/structure tool to crash.
The solution, as you discovered, is to ensure your media properties always have a value. Here are a few patterns that work well:
Provide a fallback icon:
import { DocumentIcon } from "@sanity/icons";
preview: {
select: {
title: 'title',
media: 'image'
},
prepare({title, media}) {
return {
title,
media: media ?? DocumentIcon // Fallback to an icon
}
}
}Or conditionally omit the media property:
prepare({title, media}) {
return {
title,
...(media && { media }) // Only include media if it exists
}
}This stricter validation is part of v3's move to a more predictable and type-safe architecture. While v2's webpack-based build system would sometimes silently handle these issues, v3's Vite-based build system (which is why you saw Vite in the error) is more strict about component props.
Thanks for sharing the solution – it'll definitely help others hitting the same issue during migration!
Show original thread7 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.