How to override the default preview configuration for an image block in Portable Text in Sanity.io
I understand the frustration! Unfortunately, what you're running into is a limitation of how Sanity's preview.select works with image assets.
The issue is that when you use dot notation like asset.altText in your select, Sanity's built-in image handling for the media field gets disrupted. The preview configuration documentation shows that while you can use dot notation to follow references (like author.name), this doesn't work smoothly when you need both the asset reference itself AND fields from that asset in the same preview.
The good news: You don't need to manually construct <img> tags or use the full-size image URL. When you use a prepare function, you can still pass the asset reference directly to media and Sanity will handle the thumbnail generation automatically:
preview: {
select: {
asset: 'asset',
alt: 'asset.altText',
},
prepare({ asset, alt }) {
return {
title: alt || 'Untitled',
media: asset, // Sanity handles thumbnailing automatically
}
}
}The key insight is that in the prepare function's return object, the media property can accept an asset reference directly—you don't need to manually extract URLs or render image components. Sanity's preview system will automatically generate an appropriately-sized thumbnail from the asset reference.
This is much simpler than your third approach with the manual <img> tag and asset.url, and it avoids loading full-size images. The limitation is that there's no pure select-only solution when you want to access both the asset reference (for thumbnail display) and fields from that asset (like altText)—you need the prepare function to handle both, but it's still quite straightforward.
If you have other asset fields you want to display, you can select them all and use them in the prepare function:
preview: {
select: {
asset: 'asset',
alt: 'asset.altText',
filename: 'asset.originalFilename',
},
prepare({ asset, alt, filename }) {
return {
title: alt || filename || 'Untitled',
subtitle: filename,
media: asset,
}
}
}This gives you full control over how asset metadata is displayed while still leveraging Sanity's built-in thumbnail handling.
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.